24
24
import java .util .Arrays ;
25
25
import java .util .Map ;
26
26
27
+ import org .eclipse .keti .acs .commons .web .AcsApiUriTemplates ;
28
+ import org .eclipse .keti .acs .model .Attribute ;
29
+ import org .eclipse .keti .acs .model .Effect ;
30
+ import org .eclipse .keti .acs .rest .BaseResource ;
31
+ import org .eclipse .keti .acs .rest .BaseSubject ;
32
+ import org .eclipse .keti .acs .rest .PolicyEvaluationRequestV1 ;
33
+ import org .eclipse .keti .acs .rest .PolicyEvaluationResult ;
34
+ import org .eclipse .keti .test .utils .ACSITSetUpFactory ;
35
+ import org .eclipse .keti .test .utils .PolicyHelper ;
36
+ import org .eclipse .keti .test .utils .PrivilegeHelper ;
37
+ import org .slf4j .Logger ;
38
+ import org .slf4j .LoggerFactory ;
27
39
import org .springframework .beans .factory .annotation .Autowired ;
28
40
import org .springframework .core .env .Environment ;
29
41
import org .springframework .http .HttpEntity ;
43
55
import org .testng .annotations .DataProvider ;
44
56
import org .testng .annotations .Test ;
45
57
46
- import org .eclipse .keti .acs .commons .web .AcsApiUriTemplates ;
47
- import org .eclipse .keti .acs .model .Attribute ;
48
- import org .eclipse .keti .acs .model .Effect ;
49
- import org .eclipse .keti .acs .rest .BaseResource ;
50
- import org .eclipse .keti .acs .rest .BaseSubject ;
51
- import org .eclipse .keti .acs .rest .PolicyEvaluationRequestV1 ;
52
- import org .eclipse .keti .acs .rest .PolicyEvaluationResult ;
53
- import org .eclipse .keti .test .utils .ACSITSetUpFactory ;
54
- import org .eclipse .keti .test .utils .PolicyHelper ;
55
- import org .eclipse .keti .test .utils .PrivilegeHelper ;
56
-
57
58
/**
58
59
59
60
*/
@@ -79,6 +80,8 @@ public class ACSAcceptanceIT extends AbstractTestNGSpringContextTests {
79
80
80
81
private HttpHeaders headersWithZoneSubdomain ;
81
82
83
+ private static final Logger LOGGER = LoggerFactory .getLogger (ACSAcceptanceIT .class );
84
+
82
85
@ BeforeClass
83
86
public void setup () throws IOException {
84
87
this .acsitSetUpFactory .setUp ();
@@ -117,40 +120,44 @@ public void testAcsHealth() {
117
120
118
121
@ Test (dataProvider = "endpointProvider" )
119
122
public void testCompleteACSFlow (final String endpoint , final HttpHeaders headers ,
120
- final PolicyEvaluationRequestV1 policyEvalRequest , final String subjectIdentifier ) throws Exception {
123
+ final PolicyEvaluationRequestV1 policyEvalRequest , final Effect expectedEffect ) throws Exception {
121
124
122
125
String testPolicyName = null ;
123
- BaseSubject marissa = null ;
124
- BaseResource testResource = null ;
126
+ BaseSubject bob = null ;
127
+ BaseResource alarms = null ;
125
128
try {
129
+ LOGGER .info ("Adding a policy 'Subjects can access resource if they are assigned to the same site'." );
126
130
testPolicyName = this .policyHelper .setTestPolicy (this .acsZoneRestTemplate , headers , endpoint ,
127
131
"src/test/resources/testCompleteACSFlow.json" );
128
- BaseSubject subject = new BaseSubject (subjectIdentifier );
132
+ BaseSubject subject = new BaseSubject (policyEvalRequest . getSubjectIdentifier () );
129
133
Attribute site = new Attribute ();
130
134
site .setIssuer ("issuerId1" );
131
135
site .setName ("site" );
132
136
site .setValue ("sanramon" );
133
137
134
- marissa = this .privilegeHelper .putSubject (this .acsZoneRestTemplate , subject , endpoint , headers , site );
135
-
136
- Attribute region = new Attribute ();
137
- region .setIssuer ("issuerId1" );
138
- region .setName ("region" );
139
- region .setValue ("testregion" ); // test policy asserts on this value
138
+ LOGGER .info ("Adding a subject '{}' assigned to a site '{}'." , subject .getSubjectIdentifier (),
139
+ site .getValue ());
140
+ bob = this .privilegeHelper .putSubject (this .acsZoneRestTemplate , subject , endpoint , headers , site );
140
141
141
142
BaseResource resource = new BaseResource ();
142
- resource .setResourceIdentifier ("/alarms/sites/sanramon" );
143
+ resource .setResourceIdentifier (policyEvalRequest . getResourceIdentifier () );
143
144
144
- testResource = this .privilegeHelper .putResource (this .acsZoneRestTemplate , resource , endpoint , headers ,
145
- region );
145
+ LOGGER .info ("Adding a resource '{}'." , resource .getResourceIdentifier ());
146
+ alarms = this .privilegeHelper .putResource (this .acsZoneRestTemplate , resource , endpoint , headers ,
147
+ new Attribute ());
146
148
149
+ LOGGER .info ("Evaluating if subject '{}' has access to resource '{}'." , bob .getSubjectIdentifier (),
150
+ alarms .getResourceIdentifier ());
147
151
ResponseEntity <PolicyEvaluationResult > evalResponse = this .acsZoneRestTemplate .postForEntity (
148
152
endpoint + PolicyHelper .ACS_POLICY_EVAL_API_PATH , new HttpEntity <>(policyEvalRequest , headers ),
149
153
PolicyEvaluationResult .class );
150
154
151
155
Assert .assertEquals (evalResponse .getStatusCode (), HttpStatus .OK );
152
156
PolicyEvaluationResult responseBody = evalResponse .getBody ();
153
- Assert .assertEquals (responseBody .getEffect (), Effect .PERMIT );
157
+ LOGGER .info ("Request for subject '{}' assigned to '{}' to access resource '{}' returned '{}'." ,
158
+ bob .getSubjectIdentifier (), site .getValue (), alarms .getResourceIdentifier (),
159
+ responseBody .getEffect ().toString ());
160
+ Assert .assertEquals (responseBody .getEffect (), expectedEffect );
154
161
} finally {
155
162
// delete policy
156
163
if (null != testPolicyName ) {
@@ -159,13 +166,13 @@ public void testCompleteACSFlow(final String endpoint, final HttpHeaders headers
159
166
}
160
167
161
168
// delete attributes
162
- if (null != marissa ) {
169
+ if (null != bob ) {
163
170
this .acsZoneRestTemplate .exchange (
164
- endpoint + PrivilegeHelper .ACS_SUBJECT_API_PATH + marissa .getSubjectIdentifier (),
171
+ endpoint + PrivilegeHelper .ACS_SUBJECT_API_PATH + bob .getSubjectIdentifier (),
165
172
HttpMethod .DELETE , new HttpEntity <>(headers ), String .class );
166
173
}
167
- if (null != testResource ) {
168
- String encodedResource = URLEncoder .encode (testResource .getResourceIdentifier (), "UTF-8" );
174
+ if (null != alarms ) {
175
+ String encodedResource = URLEncoder .encode (alarms .getResourceIdentifier (), "UTF-8" );
169
176
URI uri = new URI (endpoint + PrivilegeHelper .ACS_RESOURCE_API_PATH + encodedResource );
170
177
this .acsZoneRestTemplate .exchange (uri , HttpMethod .DELETE , new HttpEntity <>(headers ), String .class );
171
178
}
@@ -174,10 +181,13 @@ public void testCompleteACSFlow(final String endpoint, final HttpHeaders headers
174
181
175
182
@ DataProvider (name = "endpointProvider" )
176
183
public Object [][] getAcsEndpoint () throws Exception {
177
- PolicyEvaluationRequestV1 policyEvalForBob = this .policyHelper .createEvalRequest ("GET" , "bob" ,
184
+ PolicyEvaluationRequestV1 policyEvalForBobPermit = this .policyHelper .createEvalRequest ("GET" , "bob" ,
178
185
"/alarms/sites/sanramon" , null );
179
-
180
- return new Object [][] { { this .acsBaseUrl , this .headersWithZoneSubdomain , policyEvalForBob , "bob" } };
186
+ PolicyEvaluationRequestV1 policyEvalForBobDeny = this .policyHelper .createEvalRequest ("GET" , "bob" ,
187
+ "/alarms/sites/newyork" , null );
188
+ return new Object [][] {
189
+ { this .acsBaseUrl , this .headersWithZoneSubdomain , policyEvalForBobPermit , Effect .PERMIT },
190
+ { this .acsBaseUrl , this .headersWithZoneSubdomain , policyEvalForBobDeny , Effect .DENY } };
181
191
}
182
192
183
193
private ResponseEntity <String > getMonitoringApiResponse (final HttpHeaders headers ) {
0 commit comments