Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit b80132c

Browse files
authored
Bug/ff 179 (#40)
* FF-179 implemented new cucumber test. * FF-179 Forgot to implement refreshToken Change on Pw change.
1 parent d1f707a commit b80132c

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

src/main/java/de/filefighter/rest/domain/user/business/UserBusinessService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void updateUser(long userId, UserRegisterForm userToUpdate, User authenti
155155
if (null == userToUpdate)
156156
throw new UserNotUpdatedException("No updates specified.");
157157

158-
if(null == authenticatedUser.getGroups())
158+
if (null == authenticatedUser.getGroups())
159159
throw new UserNotUpdatedException("Authenticated User is not allowed");
160160

161161
boolean authenticatedUserIsAdmin = Arrays.stream(authenticatedUser.getGroups()).anyMatch(g -> g == Groups.ADMIN);
@@ -205,6 +205,10 @@ public void updateUser(long userId, UserRegisterForm userToUpdate, User authenti
205205

206206
changesWereMade = true;
207207
newUpdate.set("password", password);
208+
209+
//update refreshToken
210+
String newRefreshToken = AccessTokenBusinessService.generateRandomTokenValue();
211+
newUpdate.set("refreshToken", newRefreshToken);
208212
}
209213

210214
// groups
@@ -222,7 +226,7 @@ public void updateUser(long userId, UserRegisterForm userToUpdate, User authenti
222226
newUpdate.set("groupIds", userToUpdate.getGroupIds());
223227
}
224228

225-
if(!changesWereMade)
229+
if (!changesWereMade)
226230
throw new UserNotUpdatedException("No changes were made.");
227231

228232
Query query = new Query();

src/test/java/de/filefighter/rest/cucumber/CommonCucumberSteps.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
import java.io.IOException;
2424
import java.util.Arrays;
2525

26-
import static org.junit.jupiter.api.Assertions.assertEquals;
27-
import static org.junit.jupiter.api.Assertions.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.*;
2827

2928
public class CommonCucumberSteps extends RestApplicationIntegrationTest {
3029

@@ -80,6 +79,18 @@ public void userWithIdExistsAndHasUsernamePassword(long userId, String username,
8079
.build()));
8180
}
8281

82+
@Autowired
83+
MongoTemplate mongoTemplate;
84+
85+
@And("user with id {long} is in group with id {long}")
86+
public void userWithIdIsInGroupWithId(long userId, long groupId) {
87+
Query query = new Query();
88+
Update newUpdate = new Update().set("groupIds", new long[]{groupId});
89+
query.addCriteria(Criteria.where("userId").is(userId));
90+
91+
mongoTemplate.findAndModify(query, newUpdate, UserEntity.class);
92+
}
93+
8394
// This step almost needs a unit test.
8495
@Given("{string} exists with id {long} and path {string}")
8596
public void fileOrFolderExistsWithIdAndPath(String fileOrFolder, long fsItemId, String path) {
@@ -171,15 +182,11 @@ public void responseContainsKeyAndValueOfAtLeast(String key, int value) throws J
171182
assertTrue(actualValue >= value);
172183
}
173184

174-
@Autowired
175-
MongoTemplate mongoTemplate;
176-
177-
@And("user with id {long} is in group with id {long}")
178-
public void userWithIdIsInGroupWithId(long userId, long groupId) {
179-
Query query = new Query();
180-
Update newUpdate = new Update().set("groupIds", new long[]{groupId});
181-
query.addCriteria(Criteria.where("userId").is(userId));
185+
@And("response contains key {string} and a different value than {string}")
186+
public void responseContainsKeyAndADifferentValueThan(String key, String differentValue) throws JsonProcessingException {
187+
JsonNode rootNode = objectMapper.readTree(latestResponse.getBody());
188+
String actualValue = rootNode.get(key).asText();
182189

183-
mongoTemplate.findAndModify(query, newUpdate, UserEntity.class);
190+
assertNotEquals(differentValue, actualValue);
184191
}
185192
}

src/test/resources/UserEditInformation.feature

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Feature: Edit User Details
44

55
Background:
66
Given database is empty
7-
And user with id 1234 exists and has username "user", password "secure_password"
7+
And user with id 1234 exists and has username "user", password "secure_password" and refreshToken "refreshToken1234"
88
And accessToken with value "accessToken" exists for user 1234
99

1010
Scenario: Successful change of username
@@ -37,3 +37,12 @@ Feature: Edit User Details
3737
Then response contains key "message" and value "User could not get updated. No changes were made."
3838
And response contains key "status" and value "Conflict"
3939
And response status code is 409
40+
41+
Scenario: RefreshToken of user is different after password change.
42+
When user requests change of password with value "newValidPassword123" userId 1234 and accessToken "accessToken"
43+
Then response contains key "message" and value "User successfully updated."
44+
And response contains key "status" and value "Created"
45+
And response status code is 201
46+
When user requests login with username "user" and password "newValidPassword123"
47+
And response contains key "tokenValue" and a different value than "refreshToken1234"
48+
Then response status code is 200

0 commit comments

Comments
 (0)