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

Commit ef759f4

Browse files
authored
Cucumber UserAuthorization (#6)
* added UserAuthorization cucumber test * FF-65 rewrote some steps, rearranged steps, create CommonCucumberSteps.java
1 parent e7ab590 commit ef759f4

10 files changed

+153
-78
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Feature: User Authorization
2+
As a user
3+
I want to be able to log in with username and password, as well as verify my identity
4+
when using the endpoints.
5+
6+
Background:
7+
Given database is empty
8+
And user with id 1234 exists and has username "user", password "secure_password" and refreshToken "token"
9+
10+
Scenario: Successful login with username and password.
11+
When user requests login with username "user" and password "secure_password"
12+
Then response contains key "refreshToken" and value "token"
13+
And response status code is 200
14+
And response contains the user with id 1234
15+
16+
Scenario: Failed login with username and password.
17+
When user requests login with username "user" and password "wrong_password"
18+
Then response contains key "message" and value "User not authenticated."
19+
And response contains key "status" and value "denied"
20+
And response status code is 401
21+
22+
Scenario: Successful retrieval of accessToken with refreshToken.
23+
When user requests accessToken with refreshToken "token" and userId 1234
24+
Then response contains key "userId" and value "1234"
25+
And response contains valid accessToken
26+
And response status code is 200
27+
28+
Scenario: Failed retrieval of accessToken with wrong refreshToken.
29+
When user requests accessToken with refreshToken "not_the_token" and userId 1234
30+
Then response contains key "message" and value "User not authenticated."
31+
And response contains key "status" and value "denied"
32+
And response status code is 401
33+
34+
Scenario: Successful UserInfo request with valid accessToken.
35+
Given user 1234 has access token "accessToken"
36+
When user requests userInfo with accessToken "accessToken" and userId 1234
37+
Then response contains the user with id 1234
38+
And response status code is 200
39+
40+
Scenario: Failed UserInfo request with invalid accessToken.
41+
When user requests userInfo with accessToken "notTheAccessToken" and userId 1234
42+
Then response contains key "message" and value "User not authenticated."
43+
And response contains key "status" and value "denied"
44+
And response status code is 401

src/test/cucumber/de/filefighter/rest/ViewFolderContents.feature

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ Scenario: Folder does not exist
2222
Given user 1234 has permission of "view" for "folder" with id 42
2323
When user with token "900000" wants to see the content of folder with path "bla/fasel"
2424
Then response status code is 400
25-
And response message contains "Folder does not exist, or you are not allowed to see the folder."
25+
And response contains key "message" and value "Folder does not exist, or you are not allowed to see the folder."
2626

2727

2828
Scenario: insufficient authorization
2929
Given user 9877 exists
3030
And user 9877 has access token "2345678"
3131
When user with token "2345678" wants to see the content of folder with path "bla"
3232
Then response status code is 400
33-
And response message contains "Folder does not exist, or you are not allowed to see the folder."
33+
And response contains key "message" and value "Folder does not exist, or you are not allowed to see the folder."
34+
3435

3536
Scenario: shared file
3637
Given "folder" exists with id 43 and path "bla"

src/test/cucumber/de/filefighter/rest/crudPermissions.feature

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ Scenario: removing not existing permission
4848
And user 9877 has no permission for "file" with id 111
4949
When user with token "900000" wants to remove permissions of "file" with id 111 for user 9877
5050
Then response status code is 400
51-
Then response message contains "Couldn't remove permission that does not exit."
51+
And response contains key "message" and value "Couldn't remove permission that does not exit."
5252

5353

5454
Scenario Outline: Successful interaction adding new permission
5555
Given "<type>" exists with id <id> and path "<path>"
5656
And user 1234 is owner of file or folder with id <id>
5757
And user 9877 has no permission for "<type>" with id <id>
58-
When user with token "900000" wants to add permissions of "<type>" with id <id> for user 9877 for "<new_permission>"
58+
When user with token "900000" wants to give "<new_permission>" permission for "<type>" with id <id> to user 9877
5959
Then response status code is 200
6060
And user 9877 has permission of "<new_permission>" for "<type>" with id <id>
6161
Examples:
@@ -70,29 +70,29 @@ Scenario: User is not owner of file
7070
Given "file" exists with id 111 and path "bla.txt"
7171
And user 3131 exists
7272
And user 9877 is owner of file or folder with id 111
73-
When user with token "900000" wants to add permissions of "file" with id 111 for user 3131 for "edit"
73+
When user with token "900000" wants to give "edit" permission for "file" with id 111 to user 3131
7474
Then response status code is 403
75-
And response message contains "User with id 1234 is not owner of file with id 111."
75+
And response contains key "message" and value "User with id 1234 is not owner of file with id 111."
7676

7777

7878
Scenario: User does not exist
7979
Given "file" exists with id 111 and path "bla.txt"
8080
And user 1234 is owner of file or folder with id 111
81-
When user with token "900000" wants to add permissions of "file" with id 111 for user 3131 for "edit"
81+
When user with token "900000" wants to give "edit" permission for "file" with id 111 to user 3131
8282
Then response status code is 404
83-
And response message contains "User 3131 does not exist."
83+
And response contains key "message" and value "User 3131 does not exist."
8484

8585

8686
Scenario: File does not exist
8787
And user 1234 is owner of file or folder with id 111
88-
When user with token "900000" wants to add permissions of "file" with id 111 for user 9877 for "edit"
88+
When user with token "900000" wants to give "edit" permission for "file" with id 111 to user 9877
8989
Then response status code is 404
90-
And response message contains "No File with id 111 found."
90+
And response contains key "message" and value "No File with id 111 found."
9191

9292

9393
Scenario: User is already owner
9494
Given "file" exists with id 111 and path "bla.txt"
9595
And user 1234 is owner of file or folder with id 111
96-
When user with token "900000" wants to add permissions of "file" with id 111 for user 1234 for "edit"
96+
When user with token "900000" wants to give "edit" permission for "file" with id 111 to user 1234
9797
Then response status code is 405
98-
And response message contains "User with id 1234 is already owner of file with id 111."
98+
And response contains key "message" and value "User with id 1234 is already owner of file with id 111."

src/test/java/de/filefighter/rest/RestApplicationIntegrationTests.java renamed to src/test/java/de/filefighter/rest/RestApplicationIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import static org.assertj.core.api.Assertions.assertThat;
1212

1313
@SpringBootTest
14-
class RestApplicationIntegrationTests {
14+
class RestApplicationIntegrationTest {
1515

1616
@Autowired
1717
SystemHealthRestController healthController;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package de.filefighter.rest.cucumber;
2+
3+
import io.cucumber.java.en.And;
4+
import io.cucumber.java.en.Given;
5+
import io.cucumber.java.en.Then;
6+
7+
public class CommonCucumberSteps extends CucumberIntegrationTest {
8+
9+
@Given("database is empty")
10+
public void databaseIsEmpty() {
11+
}
12+
13+
@And("user {long} exists")
14+
public void userExists(long userId) {
15+
}
16+
17+
@And("user {long} has access token {string}")
18+
public void userHasAccessToken(long userId, String accessTokenValue) {
19+
}
20+
21+
@And("user with id {long} exists and has username {string}, password {string} and refreshToken {string}")
22+
public void userWithIdExistsAndHasUsernamePasswordAndRefreshToken(long userId, String username, String password, String refreshTokenValue) {
23+
}
24+
25+
// file / folder
26+
@Given("{string} exists with id {long} and path {string}")
27+
public void existsWithIdAndPath(String fileOrFolder, long fsItemId, String arg2) {
28+
}
29+
30+
@And("user {long} is owner of file or folder with id {long}")
31+
public void userIsOwnerOfFileOrFolderWithId(long userId, long fsItemId) {
32+
}
33+
34+
//key: value for json type response.
35+
@Then("response contains key {string} and value {string}")
36+
public void responseContainsKeyAndValue(String key, String value) {
37+
}
38+
39+
@And("response contains the user with id {long}")
40+
public void responseContainsTheUserWithId(long userId) {
41+
}
42+
43+
@Then("response status code is {int}")
44+
public void responseStatusCodeIs(int httpStatusCode) {
45+
}
46+
47+
}
Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,32 @@
11
package de.filefighter.rest.cucumber;
22

33
import io.cucumber.java.en.And;
4-
import io.cucumber.java.en.Given;
5-
import io.cucumber.java.en.Then;
64
import io.cucumber.java.en.When;
75

8-
public class CrudPermissionSteps extends SpringIntegrationTest{
6+
public class CrudPermissionSteps extends CucumberIntegrationTest {
97

10-
// TODO: Rearrange the steps, create Shared State Handler.
11-
12-
@Given("database is empty")
13-
public void databaseIsEmpty() {
14-
}
15-
16-
@And("user {int} exists")
17-
public void userExists(int arg0) {
18-
}
19-
20-
@And("user {int} has access token {string}")
21-
public void userHasAccessToken(int arg0, String arg1) {
22-
}
23-
24-
@And("user {int} has permission of {string} for {string} with id {int}")
25-
public void userHasPermissionOfForWithIdId(int arg0, String arg1, String arg2,int arg3) {
26-
}
27-
28-
@When("user with token {string} wants to change permissions of {string} with id {int} for user with id {int} to {string}")
29-
public void userWithTokenWantsToChangePermissionsOfWithIdIdForUserWithIdTo(String arg0, String arg1, int fileID,int arg2, String arg3) {
30-
}
31-
32-
@When("user with token {string} wants to remove permissions of {string} with id {int} for user {int}")
33-
public void userWithTokenWantsToRemovePermissionsOfWithIdIdForUser(String arg0, String arg1,int fileID, int arg2) {
34-
}
35-
36-
@And("user with id {int} has no permission for {string} with id {int}")
37-
public void userWithIdHasNoPermissionForWithIdId(int arg0, String arg1, int fileID) {
38-
}
39-
40-
@Given("{string} exists with id {int} and path {string}")
41-
public void existsWithIdAndPath(String arg0, int arg1, String arg2) {
8+
@And("user {long} has permission of {string} for {string} with id {long}")
9+
public void userHasPermissionOfForWithIdId(long userId, String readOrWrite, String fileOrFolder, long fsItemId) {
4210
}
4311

44-
@And("user {int} is owner of file or folder with id {int}")
45-
public void userIsOwnerOfFileOrFolderWithId(int arg0, int arg1) {
12+
@When("user with token {string} wants to change permissions of {string} with id {long} for user with id {long} to {string}")
13+
public void userWithTokenWantsToChangePermissionsOfWithIdIdForUserWithIdTo(String accessTokenValue, String fileOrFolder, long fsItemId, long userId, String newPermission) {
4614
}
4715

48-
@And("user {int} has no permission for {string} with id {int}")
49-
public void userHasNoPermissionForWithId(int arg0, String arg1, int arg2) {
16+
@When("user with token {string} wants to remove permissions of {string} with id {long} for user {long}")
17+
public void userWithTokenWantsToRemovePermissionsOfWithIdIdForUser(String accessTokenValue, String fileOrFolder, long fsItemId, long userId) {
5018
}
5119

52-
@Then("response status code is {int}")
53-
public void responseStatusCodeIs(int arg0) {
20+
@And("user with id {long} has no permission for {string} with id {long}")
21+
public void userWithIdHasNoPermissionForWithIdId(long userId, String fileOrFolder, long fsItemId) {
5422
}
5523

56-
@Then("response message contains {string}")
57-
public void responseMessageContains(String arg0) {
24+
@And("user {long} has no permission for {string} with id {long}")
25+
public void userHasNoPermissionForWithId(long userId, String fileOrFolder, long fsItemId) {
5826
}
5927

60-
@When("user with token {string} wants to add permissions of {string} with id {int} for user {int} for {string}")
61-
public void userWithTokenWantsToAddPermissionsOfWithIdForUserFor(String arg0, String arg1, int arg2, int arg3, String arg4) {
28+
@When("user with token {string} wants to give {string} permission for {string} with id {long} to user {long}")
29+
public void userWithTokenWantsToAddPermissionsOfWithIdForUserFor(String accessTokenValue, String permission, String fileOrFolder, long fsItemId, long userId) {
6230
}
6331

6432
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import io.cucumber.junit.Cucumber;
44
import io.cucumber.junit.CucumberOptions;
5+
import io.cucumber.spring.CucumberContextConfiguration;
56
import org.junit.runner.RunWith;
7+
import org.springframework.boot.test.context.SpringBootTest;
68

9+
@CucumberContextConfiguration
10+
@SpringBootTest
711
@RunWith(Cucumber.class)
812
@CucumberOptions(features = "src/test/cucumber/de/filefighter/rest/")
913
public class CucumberIntegrationTest {
10-
}
14+
}

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

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package de.filefighter.rest.cucumber;
2+
3+
import io.cucumber.java.en.And;
4+
import io.cucumber.java.en.Then;
5+
import io.cucumber.java.en.When;
6+
7+
import static org.junit.jupiter.api.Assertions.assertTrue;
8+
9+
public class UserAuthorizationSteps extends CucumberIntegrationTest {
10+
11+
@When("user requests login with username {string} and password {string}")
12+
public void userRequestsLoginWithUsernameAndPassword(String username, String password) {
13+
}
14+
15+
@When("user requests accessToken with refreshToken {string} and userId {long}")
16+
public void userRequestsAccessTokenWithRefreshTokenAndUserId(String refreshTokenValue, long userId) {
17+
}
18+
19+
@And("response contains valid accessToken")
20+
public void responseContainsValidAccessToken() {
21+
}
22+
23+
@When("user requests userInfo with accessToken {string} and userId {long}")
24+
public void userRequestsUserInfoWithAccessTokenAndUserId(String accessTokenValue, long userId) {
25+
}
26+
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
package de.filefighter.rest.cucumber;
22

33
import io.cucumber.java.en.And;
4-
import io.cucumber.java.en.Given;
5-
import io.cucumber.java.en.Then;
64
import io.cucumber.java.en.When;
75

8-
public class ViewFolderContentsSteps extends SpringIntegrationTest{
6+
public class ViewFolderContentsSteps extends CucumberIntegrationTest {
97
@When("user with token {string} wants to see the content of folder with path {string}")
10-
public void userWithTokenWantsToSeeTheContentOfFolderWithPath(String arg0, String arg1) {
8+
public void userWithTokenWantsToSeeTheContentOfFolderWithPath(String accessTokenValue, String path) {
119
}
1210

13-
@And("the response contains the file with id {int} and name {string}")
14-
public void theResponseContainsTheFileWithIdAndName(int arg0, String arg1) {
15-
}
16-
17-
@And("in the response the file with id {int} has true for the property public")
18-
public void inTheResponseTheFileWithIdHasTrueForThePropertyPublic(int arg0) {
11+
@And("the response contains the file with id {long} and name {string}")
12+
public void theResponseContainsTheFileWithIdAndName(long fsItemId , String name) {
1913
}
2014

2115
@And("the response contains an empty list for files and folders")

0 commit comments

Comments
 (0)