Skip to content

Commit 67b006e

Browse files
author
Anders Breid
authored
Update /auth to /authentication (#265)
- Update code from /auth to /authentication - Update tests from /auth to /authentication - Update documentation from /auth to /authentication - Update some variables/files named ith auth, or faulty named variables - Improved information on assertEquals for integration tests
1 parent 2e49a52 commit 67b006e

File tree

14 files changed

+84
-78
lines changed

14 files changed

+84
-78
lines changed

src/functionaltest/java/com/ericsson/ei/frontend/SeleniumBaseClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected void initBaseMocks(CloseableHttpClient mockedHttpClient) throws Client
7676
.execute(Mockito.argThat(request -> (request).getURI().toString().contains("/status")));
7777

7878
Mockito.doReturn(responseData).when(mockedHttpClient)
79-
.execute(Mockito.argThat(request -> (request).getURI().toString().contains("/auth")));
79+
.execute(Mockito.argThat(request -> (request).getURI().toString().contains("/authentication")));
8080

8181
Mockito.doReturn(responseData).when(mockedHttpClient)
8282
.execute(Mockito.argThat(request -> (request).getURI().toString().contains("/subscriptions")));

src/functionaltest/java/com/ericsson/ei/frontend/TestSubscriptionCRUD.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class TestSubscriptionCRUD extends SeleniumBaseClass {
3232
private String responseBodyPost;
3333
private String responseBodyPut;
3434
private String responseBodyDelete;
35-
private String encodedAuth;
35+
private String encodedCredentials;
3636

3737
@Rule
3838
public MockServerRule mockServerRule = new MockServerRule(this);
@@ -47,8 +47,8 @@ public void init() throws Exception {
4747

4848
subscriptionRequestBody = getJSONStringFromFile(SUBSCRIPTION_FILE_PATH);
4949

50-
String auth = USERNAME + ":" + PASSWORD;
51-
encodedAuth = StringUtils.newStringUtf8(Base64.encodeBase64(auth.getBytes()));
50+
String credentials = USERNAME + ":" + PASSWORD;
51+
encodedCredentials = StringUtils.newStringUtf8(Base64.encodeBase64(credentials.getBytes()));
5252
responseBodyPost = new JsonParser().parse("{\"msg\": \"Inserted Successfully\"," + "\"statusCode\": 200}").toString();
5353
responseBodyPut = new JsonParser().parse("{\"msg\": \"Updated Successfully\"," + "\"statusCode\": 200}").toString();
5454
responseBodyDelete = new JsonParser().parse("{\"msg\": \"Deleted Successfully\"," + "\"statusCode\": 200}").toString();
@@ -57,7 +57,7 @@ public void init() throws Exception {
5757
@Test
5858
public void testCreateSubscriptionSuccess() throws Exception {
5959
mockSubscriptionEndpointForPostAndPut("POST", responseBodyPost);
60-
mockMvc.perform(post(SUBSCRIPTION_ENDPOINT).servletPath(SUBSCRIPTION_ENDPOINT).header(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuth)
60+
mockMvc.perform(post(SUBSCRIPTION_ENDPOINT).servletPath(SUBSCRIPTION_ENDPOINT).header(HttpHeaders.AUTHORIZATION, "Basic " + encodedCredentials)
6161
.content(subscriptionRequestBody).accept(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
6262
.andExpect(content().string(responseBodyPost)).andReturn();
6363
}
@@ -72,7 +72,7 @@ public void testCreateSubscriptionNotFound() throws Exception {
7272
@Test
7373
public void testUpdateSubscriptionSuccess() throws Exception {
7474
mockSubscriptionEndpointForPostAndPut("PUT", responseBodyPut);
75-
mockMvc.perform(put(SUBSCRIPTION_ENDPOINT).servletPath(SUBSCRIPTION_ENDPOINT).header(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuth)
75+
mockMvc.perform(put(SUBSCRIPTION_ENDPOINT).servletPath(SUBSCRIPTION_ENDPOINT).header(HttpHeaders.AUTHORIZATION, "Basic " + encodedCredentials)
7676
.content(subscriptionRequestBody).accept(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
7777
.andExpect(content().string(responseBodyPut)).andReturn();
7878
}
@@ -88,7 +88,7 @@ public void testUpdateSubscriptionNotFound() throws Exception {
8888
public void testDeleteSubscriptionSuccess() throws Exception {
8989
mockSubscriptionEndpointForDelete();
9090
mockMvc.perform(delete(SUBSCRIPTION_DELETE_ENDPOINT).servletPath(SUBSCRIPTION_DELETE_ENDPOINT)
91-
.header(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuth).accept(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
91+
.header(HttpHeaders.AUTHORIZATION, "Basic " + encodedCredentials).accept(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
9292
.andExpect(content().string(responseBodyDelete)).andReturn();
9393
}
9494

@@ -103,7 +103,7 @@ public void testDeleteSubscriptionNotFound() throws Exception {
103103
public void testGetSubscriptionSuccess() throws Exception {
104104
mockSubscriptionEndpointForGet();
105105
mockMvc.perform(MockMvcRequestBuilders.get(SUBSCRIPTION_DELETE_ENDPOINT).servletPath(SUBSCRIPTION_DELETE_ENDPOINT)
106-
.header(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuth).accept(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
106+
.header(HttpHeaders.AUTHORIZATION, "Basic " + encodedCredentials).accept(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
107107
.andExpect(content().string(subscriptionRequestBody)).andReturn();
108108
}
109109

@@ -117,22 +117,22 @@ public void testGetSubscriptionNotFound() throws Exception {
117117
private void mockSubscriptionEndpointForPostAndPut(String method, String responseBody) {
118118
mockServerClient
119119
.when(request().withMethod(method).withPath(SUBSCRIPTION_ENDPOINT).withBody(subscriptionRequestBody)
120-
.withHeader(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuth))
121-
.respond(response().withBody(responseBody).withStatusCode(200).withHeader(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuth));
120+
.withHeader(HttpHeaders.AUTHORIZATION, "Basic " + encodedCredentials))
121+
.respond(response().withBody(responseBody).withStatusCode(200).withHeader(HttpHeaders.AUTHORIZATION, "Basic " + encodedCredentials));
122122
}
123123

124124
private void mockSubscriptionEndpointForDelete() {
125125
mockServerClient
126126
.when(request().withMethod("DELETE").withPath(SUBSCRIPTION_DELETE_ENDPOINT).withHeader(HttpHeaders.AUTHORIZATION,
127-
"Basic " + encodedAuth))
128-
.respond(response().withBody(responseBodyDelete).withStatusCode(200).withHeader(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuth));
127+
"Basic " + encodedCredentials))
128+
.respond(response().withBody(responseBodyDelete).withStatusCode(200).withHeader(HttpHeaders.AUTHORIZATION, "Basic " + encodedCredentials));
129129
}
130130

131131
private void mockSubscriptionEndpointForGet() {
132132
mockServerClient
133133
.when(request().withMethod("GET").withPath(SUBSCRIPTION_DELETE_ENDPOINT).withHeader(HttpHeaders.AUTHORIZATION,
134-
"Basic " + encodedAuth))
134+
"Basic " + encodedCredentials))
135135
.respond(response().withBody(subscriptionRequestBody).withStatusCode(200).withHeader(HttpHeaders.AUTHORIZATION,
136-
"Basic " + encodedAuth));
136+
"Basic " + encodedCredentials));
137137
}
138138
}

src/functionaltest/java/com/ericsson/ei/frontend/TestSubscriptionHandling.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ private void verifyUnauthorizedSubscriptionCRUD() {
308308
assert (subscriptionPage.buttonDisabledByXPath(DELETE_BUTTON_XPATH2));
309309
}
310310

311-
private void setupMockEndpoints(boolean security, String user) throws IOException {
311+
private void setupMockEndpoints(boolean security, String userName) throws IOException {
312312
clientAndServer.clear(request());
313313
String subscriptionResponse = getJSONStringFromFile(
314314
SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP);
@@ -345,12 +345,12 @@ private void setupMockEndpoints(boolean security, String user) throws IOExceptio
345345
request().withMethod("GET").withPath("/templates/subscriptions"))
346346
.respond(response().withStatusCode(200).withBody(mockedTemplateResponse));
347347

348-
String responseAuth = "{\"security\":" + security + "}";
349-
String responseUser = "{\"user\":\"" + user + "\"}";
350-
clientAndServer.when(request().withMethod("GET").withPath("/auth"))
351-
.respond(response().withStatusCode(200).withBody(responseAuth));
352-
clientAndServer.when(request().withMethod("GET").withPath("/auth/login"))
353-
.respond(response().withStatusCode(200).withBody(responseUser));
348+
String responseSecurityStatus = "{\"security\":" + security + "}";
349+
String responseLoggedInUserName = "{\"user\":\"" + userName + "\"}";
350+
clientAndServer.when(request().withMethod("GET").withPath("/authentication"))
351+
.respond(response().withStatusCode(200).withBody(responseSecurityStatus));
352+
clientAndServer.when(request().withMethod("GET").withPath("/authentication/login"))
353+
.respond(response().withStatusCode(200).withBody(responseLoggedInUserName));
354354
}
355355

356356
private void setupMockEndpointMultiSubscription() throws IOException {

src/functionaltest/java/com/ericsson/ei/frontend/TestSwitchBackend.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private void addBackendInstances() {
129129
private static void setupMockEndpoints() throws IOException {
130130
mockClient2.when(request().withMethod("GET").withPath("/status")).respond(response().withStatusCode(200).withBody("{\"eiffelIntelligenceStatus\" : \"AVAILABLE\"}"));
131131

132-
mockClient2.when(request().withMethod("GET").withPath("/auth")).respond(response().withStatusCode(200).withBody("{\"security\":false}"));
132+
mockClient2.when(request().withMethod("GET").withPath("/authentication")).respond(response().withStatusCode(200).withBody("{\"security\":false}"));
133133

134134
String newInstanceSubscriptionResponse = getJSONStringFromFile(NEW_INSTANCE_SUBSCRIPTION_RESPONSE_FILEPATH);
135135
mockClient2.when(request().withMethod("GET").withPath("/subscriptions"))
@@ -141,6 +141,6 @@ private static void setupMockEndpoints() throws IOException {
141141

142142
mockClient1.when(request().withMethod("GET").withPath("/status")).respond(response().withStatusCode(200).withBody("{\"eiffelIntelligenceStatus\" : \"AVAILABLE\"}"));
143143

144-
mockClient1.when(request().withMethod("GET").withPath("/auth")).respond(response().withStatusCode(200).withBody("{\"security\":false}"));
144+
mockClient1.when(request().withMethod("GET").withPath("/authentication")).respond(response().withStatusCode(200).withBody("{\"security\":false}"));
145145
}
146146
}

src/integrationtest/java/com/ericsson/ei/frontend/AuthRunnerIT.java renamed to src/integrationtest/java/com/ericsson/ei/frontend/AuthenticationRunnerIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import cucumber.api.junit.Cucumber;
77

88
@RunWith(Cucumber.class)
9-
@CucumberOptions(features = "src/integrationtest/resources/features/auth.feature", glue = {
9+
@CucumberOptions(features = "src/integrationtest/resources/features/authentication.feature", glue = {
1010
"com.ericsson.ei.frontend" }, plugin = {
11-
"html:target/cucumber-reports/AuthRunnerIT" })
12-
public class AuthRunnerIT {
11+
"html:target/cucumber-reports/AuthenticationRunnerIT" })
12+
public class AuthenticationRunnerIT {
1313

1414
}

src/integrationtest/java/com/ericsson/ei/frontend/CommonSteps.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void request_sent_body_not_received(int seconds, int statusCode) throws T
165165
do {
166166
response = httpRequest.performRequest();
167167
} while (response.getStatusCode() == statusCode && stopTime > System.currentTimeMillis());
168-
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
168+
assertEquals("Response code for URL: " + getUrl(), HttpStatus.OK.value(), response.getStatusCode());
169169
}
170170

171171
@Then("^request is saved to request list at index (\\d+)$")
@@ -177,13 +177,13 @@ public void request_is_saved_to_list(int index) throws Throwable {
177177
@Then("^response code (\\d+) is received$")
178178
public void get_response_code(int statusCode) throws Throwable {
179179
LOGGER.debug("Response code: {}", response.getStatusCode());
180-
assertEquals(statusCode, response.getStatusCode());
180+
assertEquals("Response code for URL: " + getUrl(), statusCode, response.getStatusCode());
181181
}
182182

183183
@Then("^response body \'(.*)\' is received$")
184184
public void get_response_body(String body) throws Throwable {
185185
LOGGER.debug("Response body: {}", response.getBody());
186-
assertEquals(body, response.getBody());
186+
assertEquals("Response body for URL: " + getUrl(), body, response.getBody());
187187
}
188188

189189
@Then("^response body from file \'(.*)\' is received$")
@@ -192,25 +192,30 @@ public void get_response_body_from_file(String filename) throws Throwable {
192192
String fileContent = FileUtils.readFileToString(new File(filePath), "UTF-8");
193193
LOGGER.debug("File path: {}", filePath);
194194
LOGGER.debug("Response body: {}", response.getBody());
195-
assertEquals(fileContent.replaceAll("\\s+", ""), response.getBody().replaceAll("\\s+", ""));
195+
assertEquals("File content", fileContent.replaceAll("\\s+", ""), response.getBody().replaceAll("\\s+", ""));
196196
}
197197

198198
@Then("^response body contains \'(.*)\'$")
199-
public void response_body_contains(String contains) throws Throwable {
199+
public void response_body_contains(String value) throws Throwable {
200200
LOGGER.debug("Response body: {}", response.getBody());
201-
LOGGER.debug("Contains: {}", contains);
202-
assertEquals(true, response.getBody().contains(contains));
201+
LOGGER.debug("Contains: {}", value);
202+
assertEquals("Response body to contain '" + value + "'", true, response.getBody().contains(value));
203203
}
204204

205205
@Then("^response body does not contain \'(.*)\'$")
206-
public void response_body_does_not_contain(String contains) throws Throwable {
206+
public void response_body_does_not_contain(String value) throws Throwable {
207207
LOGGER.info("Response body: {}", response.getBody());
208-
LOGGER.info("Does not contain: {}", contains);
209-
assertEquals(true, !response.getBody().contains(contains));
208+
LOGGER.info("Does not contain: {}", value);
209+
assertEquals("Response body not to contain '" + value + "'", true, !response.getBody().contains(value));
210210
}
211211

212212
@Then("^remove \'(.*)\' from request headers at list index (\\d+)$")
213213
public void remove_key_from_request_headers_at_list_index(String headerKey, int index) {
214214
httpRequestList.get(index).removeHeader(headerKey);
215215
}
216+
217+
private String getUrl() {
218+
final String url = String.format("%s%s", httpRequest.getBaseUrl(), httpRequest.getEndpoint());
219+
return url;
220+
}
216221
}

src/integrationtest/resources/features/auth.feature renamed to src/integrationtest/resources/features/authentication.feature

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
@AuthFeature
1+
@AuthenticationFeature
22
Feature: Authentication test
33

4-
@AuthCheckSecurityScenario
4+
@AuthenticationCheckSecurityScenario
55
Scenario: Check security
66
Given frontend is up and running
7-
When a 'GET' request is prepared for REST API '/auth'
7+
When a 'GET' request is prepared for REST API '/authentication'
88
And request is sent
99
Then response code 200 is received
1010
And response body '{"security":true}' is received
1111

12-
@AuthMultipleUsersLoginAndLogoutScenario
12+
@AuthenticationMultipleUsersLoginAndLogoutScenario
1313
Scenario: Multiple Users Login And Logout test
1414
Given frontend is up and running
1515

1616
# Action: First user logging in
17-
When a 'GET' request is prepared for REST API '/auth/login'
17+
When a 'GET' request is prepared for REST API '/authentication/login'
1818
And username "gauss" and password "password" is used as credentials
1919
Then request is saved to request list at index 0
2020
When request is performed from request list at index 0
@@ -23,7 +23,7 @@ Feature: Authentication test
2323
And remove 'Authorization' from request headers at list index 0
2424

2525
# Action: Second user logging in
26-
When a 'GET' request is prepared for REST API '/auth/login'
26+
When a 'GET' request is prepared for REST API '/authentication/login'
2727
And username "newton" and password "password" is used as credentials
2828
Then request is saved to request list at index 1
2929
When request is performed from request list at index 1
@@ -37,7 +37,7 @@ Feature: Authentication test
3737
And response body '{"user":"gauss"}' is received
3838

3939
# Action: First user logging out
40-
When '/auth/logout' endpoint is set in request list at index 0
40+
When '/authentication/logout' endpoint is set in request list at index 0
4141
And request is performed from request list at index 0
4242
Then response code 204 is received
4343

@@ -47,17 +47,17 @@ Feature: Authentication test
4747
And response body '{"user":"newton"}' is received
4848

4949
# Check: First user proved logged out
50-
When '/auth/login' endpoint is set in request list at index 0
50+
When '/authentication/login' endpoint is set in request list at index 0
5151
And request is performed from request list at index 0
5252
Then response code 401 is received
5353

5454
# Action: Second user logging out
55-
When '/auth/logout' endpoint is set in request list at index 1
55+
When '/authentication/logout' endpoint is set in request list at index 1
5656
And request is performed from request list at index 1
5757
Then response code 204 is received
5858

5959
# Check: Second user proved logged out
60-
When '/auth/login' endpoint is set in request list at index 1
60+
When '/authentication/login' endpoint is set in request list at index 1
6161
And request is performed from request list at index 1
6262
Then response code 401 is received
6363

@@ -66,62 +66,62 @@ Feature: Authentication test
6666
Given frontend is up and running
6767

6868
# Invalid Username
69-
When a 'GET' request is prepared for REST API '/auth/login'
69+
When a 'GET' request is prepared for REST API '/authentication/login'
7070
And username "invalid_username" and password "password" is used as credentials
7171
And request is sent
7272
Then response code 401 is received
7373

7474
# Invalid Password
75-
When a 'GET' request is prepared for REST API '/auth/login'
75+
When a 'GET' request is prepared for REST API '/authentication/login'
7676
And username "gauss" and password "invalid_password" is used as credentials
7777
And request is sent
7878
Then response code 401 is received
7979

8080
@AuthUniqueUsersInDifferentLDAPServers
8181
Scenario: Login using unique users from two different LDAP servers
8282
# Action: First user logging in on first LDAP
83-
When a 'GET' request is prepared for REST API '/auth/login'
83+
When a 'GET' request is prepared for REST API '/authentication/login'
8484
And username "gauss" and password "password" is used as credentials
8585
Then request is saved to request list at index 0
8686
When request is performed from request list at index 0
8787
Then response code 200 is received
8888
And response body '{"user":"gauss"}' is received
8989

9090
# Action: First user logging out
91-
When '/auth/logout' endpoint is set in request list at index 0
91+
When '/authentication/logout' endpoint is set in request list at index 0
9292
And request is performed from request list at index 0
9393
Then response code 204 is received
9494

9595
# Action: Second user logging in on second LDAP
96-
When a 'GET' request is prepared for REST API '/auth/login'
96+
When a 'GET' request is prepared for REST API '/authentication/login'
9797
And username "einstein" and password "e=mc2" is used as credentials
9898
Then request is saved to request list at index 0
9999
When request is performed from request list at index 0
100100
Then response code 200 is received
101101
And response body '{"user":"einstein"}' is received
102102

103103
# Action: Second user logging out
104-
When '/auth/logout' endpoint is set in request list at index 0
104+
When '/authentication/logout' endpoint is set in request list at index 0
105105
And request is performed from request list at index 0
106106
Then response code 204 is received
107107

108108
@AuthIdenticalUsernamesInDifferentLDAPServers
109109
Scenario: Login using identical usernames with different passwords from two different LDAP servers
110110
# Action: User logging in on first LDAP
111-
When a 'GET' request is prepared for REST API '/auth/login'
111+
When a 'GET' request is prepared for REST API '/authentication/login'
112112
And username "newton" and password "password" is used as credentials
113113
Then request is saved to request list at index 0
114114
When request is performed from request list at index 0
115115
Then response code 200 is received
116116
And response body '{"user":"newton"}' is received
117117

118118
# Action: User logging out
119-
When '/auth/logout' endpoint is set in request list at index 0
119+
When '/authentication/logout' endpoint is set in request list at index 0
120120
And request is performed from request list at index 0
121121
Then response code 204 is received
122122

123123
# Action: User logging in on second LDAP
124-
When a 'GET' request is prepared for REST API '/auth/login'
124+
When a 'GET' request is prepared for REST API '/authentication/login'
125125
And username "newton" and password "password2" is used as credentials
126126
Then request is saved to request list at index 0
127127
When request is performed from request list at index 0

0 commit comments

Comments
 (0)