Skip to content

Commit f2c323b

Browse files
author
Irina
committed
Added negative test case and verbose output to acceptance tests. Updated version.
1 parent d719a66 commit f2c323b

File tree

7 files changed

+57
-57
lines changed

7 files changed

+57
-57
lines changed

acs-integration-tests/pom.xml

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!--
43
- Copyright 2018 General Electric Company
54
-
@@ -17,7 +16,6 @@
1716
-
1817
- SPDX-License-Identifier: Apache-2.0
1918
-->
20-
2119
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2220
<modelVersion>4.0.0</modelVersion>
2321
<artifactId>acs-integration-tests</artifactId>
@@ -27,7 +25,7 @@
2725
<parent>
2826
<groupId>org.eclipse.keti</groupId>
2927
<artifactId>acs</artifactId>
30-
<version>5.0.5-SNAPSHOT</version>
28+
<version>5.0.6-SNAPSHOT</version>
3129
<relativePath>../</relativePath>
3230
</parent>
3331

@@ -215,7 +213,7 @@
215213
<dependency>
216214
<groupId>org.eclipse.keti</groupId>
217215
<artifactId>acs-service</artifactId>
218-
<version>5.0.5-SNAPSHOT</version>
216+
<version>5.0.6-SNAPSHOT</version>
219217
<exclusions>
220218
<exclusion>
221219
<groupId>io.netty</groupId>

acs-integration-tests/src/test/java/org/eclipse/keti/acceptance/test/ACSAcceptanceIT.java

+42-32
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
import java.util.Arrays;
2525
import java.util.Map;
2626

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;
2739
import org.springframework.beans.factory.annotation.Autowired;
2840
import org.springframework.core.env.Environment;
2941
import org.springframework.http.HttpEntity;
@@ -43,17 +55,6 @@
4355
import org.testng.annotations.DataProvider;
4456
import org.testng.annotations.Test;
4557

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-
5758
/**
5859
5960
*/
@@ -79,6 +80,8 @@ public class ACSAcceptanceIT extends AbstractTestNGSpringContextTests {
7980

8081
private HttpHeaders headersWithZoneSubdomain;
8182

83+
private static final Logger LOGGER = LoggerFactory.getLogger(ACSAcceptanceIT.class);
84+
8285
@BeforeClass
8386
public void setup() throws IOException {
8487
this.acsitSetUpFactory.setUp();
@@ -117,40 +120,44 @@ public void testAcsHealth() {
117120

118121
@Test(dataProvider = "endpointProvider")
119122
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 {
121124

122125
String testPolicyName = null;
123-
BaseSubject marissa = null;
124-
BaseResource testResource = null;
126+
BaseSubject bob = null;
127+
BaseResource alarms = null;
125128
try {
129+
LOGGER.info("Adding a policy 'Subjects can access resource if they are assigned to the same site'.");
126130
testPolicyName = this.policyHelper.setTestPolicy(this.acsZoneRestTemplate, headers, endpoint,
127131
"src/test/resources/testCompleteACSFlow.json");
128-
BaseSubject subject = new BaseSubject(subjectIdentifier);
132+
BaseSubject subject = new BaseSubject(policyEvalRequest.getSubjectIdentifier());
129133
Attribute site = new Attribute();
130134
site.setIssuer("issuerId1");
131135
site.setName("site");
132136
site.setValue("sanramon");
133137

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);
140141

141142
BaseResource resource = new BaseResource();
142-
resource.setResourceIdentifier("/alarms/sites/sanramon");
143+
resource.setResourceIdentifier(policyEvalRequest.getResourceIdentifier());
143144

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());
146148

149+
LOGGER.info("Evaluating if subject '{}' has access to resource '{}'.", bob.getSubjectIdentifier(),
150+
alarms.getResourceIdentifier());
147151
ResponseEntity<PolicyEvaluationResult> evalResponse = this.acsZoneRestTemplate.postForEntity(
148152
endpoint + PolicyHelper.ACS_POLICY_EVAL_API_PATH, new HttpEntity<>(policyEvalRequest, headers),
149153
PolicyEvaluationResult.class);
150154

151155
Assert.assertEquals(evalResponse.getStatusCode(), HttpStatus.OK);
152156
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);
154161
} finally {
155162
// delete policy
156163
if (null != testPolicyName) {
@@ -159,13 +166,13 @@ public void testCompleteACSFlow(final String endpoint, final HttpHeaders headers
159166
}
160167

161168
// delete attributes
162-
if (null != marissa) {
169+
if (null != bob) {
163170
this.acsZoneRestTemplate.exchange(
164-
endpoint + PrivilegeHelper.ACS_SUBJECT_API_PATH + marissa.getSubjectIdentifier(),
171+
endpoint + PrivilegeHelper.ACS_SUBJECT_API_PATH + bob.getSubjectIdentifier(),
165172
HttpMethod.DELETE, new HttpEntity<>(headers), String.class);
166173
}
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");
169176
URI uri = new URI(endpoint + PrivilegeHelper.ACS_RESOURCE_API_PATH + encodedResource);
170177
this.acsZoneRestTemplate.exchange(uri, HttpMethod.DELETE, new HttpEntity<>(headers), String.class);
171178
}
@@ -174,10 +181,13 @@ public void testCompleteACSFlow(final String endpoint, final HttpHeaders headers
174181

175182
@DataProvider(name = "endpointProvider")
176183
public Object[][] getAcsEndpoint() throws Exception {
177-
PolicyEvaluationRequestV1 policyEvalForBob = this.policyHelper.createEvalRequest("GET", "bob",
184+
PolicyEvaluationRequestV1 policyEvalForBobPermit = this.policyHelper.createEvalRequest("GET", "bob",
178185
"/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 } };
181191
}
182192

183193
private ResponseEntity<String> getMonitoringApiResponse(final HttpHeaders headers) {

acs-integration-tests/src/test/resources/testCompleteACSFlow.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
"name" : "testCompleteACSFlow",
33
"policies" : [
44
{
5+
"name" : "Subjects can access resource if they are assigned to the same site",
56
"target" : {
7+
"action" : "GET",
68
"resource" : {
7-
"uriTemplate" : "/alarms/sites/{site_id}",
8-
"attributes" : [
9-
{
10-
"issuer":"issuerId1",
11-
"name":"region"
12-
}
13-
]
9+
"uriTemplate" : "/alarms/sites/{site_id}"
1410
},
15-
"action" : "GET",
1611
"subject" : {
1712
"attributes" : [
1813
{
@@ -25,10 +20,15 @@
2520
"conditions" : [
2621
{
2722
"condition" :
28-
"match.single(subject.attributes('issuerId1', 'site'), resource.uriVariable('site_id')) & resource.attributes('issuerId1','region').contains('testregion')"
23+
"match.single(subject.attributes('issuerId1', 'site'), resource.uriVariable('site_id'))"
2924
}
3025
],
3126
"effect" : "PERMIT"
3227
}
28+
,
29+
{
30+
"name" : "deny-all-policy",
31+
"effect" : "DENY"
32+
}
3333
]
3434
}

commons/pom.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!--
43
- Copyright 2018 General Electric Company
54
-
@@ -17,14 +16,13 @@
1716
-
1817
- SPDX-License-Identifier: Apache-2.0
1918
-->
20-
2119
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2220

2321
<modelVersion>4.0.0</modelVersion>
2422
<parent>
2523
<groupId>org.eclipse.keti</groupId>
2624
<artifactId>acs</artifactId>
27-
<version>5.0.5-SNAPSHOT</version>
25+
<version>5.0.6-SNAPSHOT</version>
2826
<relativePath>../</relativePath>
2927
</parent>
3028

model/pom.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!--
43
- Copyright 2018 General Electric Company
54
-
@@ -17,14 +16,13 @@
1716
-
1817
- SPDX-License-Identifier: Apache-2.0
1918
-->
20-
2119
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2220

2321
<modelVersion>4.0.0</modelVersion>
2422
<parent>
2523
<groupId>org.eclipse.keti</groupId>
2624
<artifactId>acs</artifactId>
27-
<version>5.0.5-SNAPSHOT</version>
25+
<version>5.0.6-SNAPSHOT</version>
2826
<relativePath>../</relativePath>
2927
</parent>
3028

pom.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!--
43
- Copyright 2018 General Electric Company
54
-
@@ -17,7 +16,6 @@
1716
-
1817
- SPDX-License-Identifier: Apache-2.0
1918
-->
20-
2119
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2220
<modelVersion>4.0.0</modelVersion>
2321
<organization>
@@ -27,7 +25,7 @@
2725
<!-- Project information necessary to deploy to Maven Central (see: http://central.sonatype.org/pages/requirements.html) -->
2826
<groupId>org.eclipse.keti</groupId>
2927
<artifactId>acs</artifactId>
30-
<version>5.0.5-SNAPSHOT</version>
28+
<version>5.0.6-SNAPSHOT</version>
3129
<packaging>pom</packaging>
3230
<name>Predix Access Control Services Parent</name>
3331
<description>Service to enforce authentication and/or authorization of certain resources</description>

service/pom.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!--
43
- Copyright 2018 General Electric Company
54
-
@@ -17,14 +16,13 @@
1716
-
1817
- SPDX-License-Identifier: Apache-2.0
1918
-->
20-
2119
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2220

2321
<modelVersion>4.0.0</modelVersion>
2422
<parent>
2523
<groupId>org.eclipse.keti</groupId>
2624
<artifactId>acs</artifactId>
27-
<version>5.0.5-SNAPSHOT</version>
25+
<version>5.0.6-SNAPSHOT</version>
2826
<relativePath>../</relativePath>
2927
</parent>
3028
<artifactId>acs-service</artifactId>

0 commit comments

Comments
 (0)