2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.cadi.oauth.test;
24 import static org.hamcrest.CoreMatchers.*;
25 import static org.junit.Assert.*;
28 import java.io.StringReader;
30 import org.onap.aaf.cadi.Permission;
31 import org.onap.aaf.cadi.oauth.TokenPerm.LoadPermissions;
32 import org.onap.aaf.misc.rosetta.ParseException;
34 public class JU_TokenPerm {
37 public void test() throws ParseException {
42 json = "{\"perm\":[" +
43 " {\"type\":\"com.access\",\"instance\":\"*\",\"action\":\"read,approve\"}," +
46 lp = new LoadPermissions(new StringReader(json));
47 assertThat(lp.perms.size(), is(1));
50 assertThat(p.getKey(), is("com.access|*|read,approve"));
51 assertThat(p.permType(), is("AAF"));
53 // Extra closing braces for coverage
54 json = "{\"perm\":[" +
55 " {\"type\":\"com.access\",\"instance\":\"*\",\"action\":\"read,approve\"}}," +
58 lp = new LoadPermissions(new StringReader(json));
59 assertThat(lp.perms.size(), is(1));
62 assertThat(p.getKey(), is("com.access|*|read,approve"));
63 assertThat(p.permType(), is("AAF"));
65 // Test without a type
66 json = "{\"perm\":[" +
67 " {\"instance\":\"*\",\"action\":\"read,approve\"}," +
70 lp = new LoadPermissions(new StringReader(json));
71 assertThat(lp.perms.size(), is(0));
73 // Test without an instance
74 json = "{\"perm\":[" +
75 " {\"type\":\"com.access\",\"action\":\"read,approve\"}," +
78 lp = new LoadPermissions(new StringReader(json));
79 assertThat(lp.perms.size(), is(0));
81 // Test without an action
82 json = "{\"perm\":[" +
83 " {\"type\":\"com.access\",\"instance\":\"*\"}," +
86 lp = new LoadPermissions(new StringReader(json));
87 assertThat(lp.perms.size(), is(0));
91 public void redundancyTest() {
92 String json = "{\"perm\":[" +
93 " {\"type\":\"com.access\",\"instance\":\"*\",\"action\":\"read,approve\"}," +
94 " {\"type\":\"org.osaaf.aaf.access\",\"instance\":\"*\",\"action\":\"*\"}," +
95 " {\"type\":\"org.osaaf.aaf.access\",\"instance\":\"*\",\"action\":\"read\"}," +
96 " {\"type\":\"org.osaaf.aaf.attrib\",\"instance\":\":com.att.*:swm\",\"action\":\"*\"}," +
97 " {\"type\":\"org.osaaf.aaf.bogus\",\"instance\":\"sample\",\"action\":\"read\"}," +
98 " {\"type\":\"org.osaaf.aaf.ca\",\"instance\":\"aaf\",\"action\":\"ip\"}," +
99 " {\"type\":\"org.osaaf.aaf.ca\",\"instance\":\"local\",\"action\":\"domain\"}," +
100 " {\"type\":\"org.osaaf.aaf.cache\",\"instance\":\"*\",\"action\":\"clear\"}," +
101 " {\"type\":\"org.osaaf.aaf.cass\",\"instance\":\":mithril\",\"action\":\"*\"}," +
102 " {\"type\":\"org.osaaf.aaf.certman\",\"instance\":\"local\",\"action\":\"read,request,showpass\"}," +
103 " {\"type\":\"org.osaaf.aaf.db\",\"instance\":\"pool\",\"action\":\"clear\"}," +
104 " {\"type\":\"org.osaaf.aaf.deny\",\"instance\":\"com.att\",\"action\":\"*\"}," +
105 " {\"type\":\"org.osaaf.aaf.jenkins\",\"instance\":\"mithrilcsp.sbc.com\",\"action\":\"admin\"}," +
106 " {\"type\":\"org.osaaf.aaf.log\",\"instance\":\"com.att\",\"action\":\"id\"}," +
107 " {\"type\":\"org.osaaf.aaf.myPerm\",\"instance\":\"myInstance\",\"action\":\"myAction\"}," +
108 " {\"type\":\"org.osaaf.aaf.ns\",\"instance\":\":com.att.*:ns\",\"action\":\"write\"}," +
109 " {\"type\":\"org.osaaf.aaf.ns\",\"instance\":\":com.att:ns\",\"action\":\"write\"}," +
110 " {\"type\":\"org.osaaf.aaf.password\",\"instance\":\"com.att\",\"action\":\"extend\"}," +
111 " {\"type\":\"org.osaaf.access\",\"instance\":\"*\",\"action\":\"read\"}," +
112 " {\"type\":\"org.osaaf.authz.access\",\"instance\":\"*\",\"action\":\"read\"}," +
113 " {\"type\":\"org.osaaf.authz.dev.access\",\"instance\":\"*\",\"action\":\"*\"}," +
114 " {\"type\":\"org.osaaf.authz.swm.star\",\"instance\":\"*\",\"action\":\"*\"}," +
115 " {\"type\":\"org.osaaf.cadi.access\",\"instance\":\"*\",\"action\":\"*\"}," +
116 " {\"type\":\"org.osaaf.chris.access\",\"instance\":\"*\",\"action\":\"*\"}," +
117 " {\"type\":\"org.osaaf.csid.lab.swm.node\",\"instance\":\"*\",\"action\":\"*\"}," +
118 " {\"type\":\"org.osaaf.myapp.access\",\"instance\":\"*\",\"action\":\"*\"}," +
119 " {\"type\":\"org.osaaf.myapp.access\",\"instance\":\"*\",\"action\":\"read\"}," +
120 " {\"type\":\"org.osaaf.sample.access\",\"instance\":\"*\",\"action\":\"read\"}," +
121 " {\"type\":\"org.osaaf.sample.swm.myPerm\",\"instance\":\"*\",\"action\":\"read\"}," +
122 " {\"type\":\"org.osaaf.temp.access\",\"instance\":\"*\",\"action\":\"read\"}," +
123 " {\"type\":\"org.osaaf.test.access\",\"instance\":\"*\",\"action\":\"*\"}," +
124 " {\"type\":\"org.osaaf.test.access\",\"instance\":\"*\",\"action\":\"read\"}," +
125 " {\"type\":\"com.test.access\",\"instance\":\"*\",\"action\":\"read\"}," +
126 " {\"type\":\"com.test.access\",\"instance\":\"*\",\"action\":\"read\"}" +
129 LoadPermissions lp = new LoadPermissions(new StringReader(json));
130 assertThat(lp.perms.size(), is(34));
131 } catch (ParseException e) {
132 fail(e.getMessage());