Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
224bfd6
Added Cucumber Integration
open-schnick Oct 25, 2020
7f33384
fixed pipeline.
open-schnick Oct 27, 2020
f036deb
added missing $
open-schnick Oct 27, 2020
ccc0545
Merge branch 'master' into feature/cucumber
open-schnick Oct 27, 2020
1538bc6
FF-65 added basic steps
qvalentin Oct 27, 2020
f597f32
changed Description and addded Background
qvalentin Oct 27, 2020
c2a26e2
fixed some typos, added some comments, created steps files removed du…
open-schnick Oct 27, 2020
803a751
cleaning of .feature file
qvalentin Oct 29, 2020
32a4b22
FF-65 added bad cases for Permissions feature file
qvalentin Oct 29, 2020
85fd3df
redone ViewFolderContents.feature
qvalentin Oct 29, 2020
65fb59e
FF-65 cleaning of feature files, added java classes for steps.
open-schnick Oct 29, 2020
fb04972
ViewFolderContentsSteps now extends SpringIntegrationTest
open-schnick Oct 30, 2020
6fdcd8e
added cucumber run config.
open-schnick Oct 30, 2020
8b1e55f
added two scenarios, fixed all the datatypes (better regenerate step …
qvalentin Oct 30, 2020
64194e2
regenerate step functions and remove duplicates
qvalentin Oct 30, 2020
45ec1b0
FF-65 fixed test failure because of duplicate step function
qvalentin Oct 30, 2020
e958e2e
FF-65 fixed steps, added comments.
open-schnick Oct 31, 2020
6c222bc
renamed role to group
open-schnick Oct 31, 2020
7fe02eb
fixed deletion of line
qvalentin Oct 31, 2020
58149ed
Merge branch 'master' into feature/cucumber
open-schnick Oct 31, 2020
2dd7855
Merge remote-tracking branch 'origin/feature/cucumber' into feature/c…
open-schnick Oct 31, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .run/RestApplication.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="RestApplication[DEV]" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<configuration name="RestApplication[DEV]" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<module name="rest" />
<option name="SPRING_BOOT_MAIN_CLASS" value="de.filefighter.rest.RestApplication" />
<option name="ACTIVE_PROFILES" value="dev" />
Expand Down
16 changes: 16 additions & 0 deletions .run/Run all Cucumber Tests.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run all Cucumber Tests" type="CucumberJavaRunConfigurationType" factoryName="Cucumber java">
<envs>
<env name="SPRING_PROFILES_ACTIVE" value="&quot;dev&quot;" />
</envs>
<option name="FILE_PATH" value="$PROJECT_DIR$/src/test/cucumber/de/filefighter/rest" />
<option name="GLUE" value="de.filefighter.rest.cucumber" />
<option name="MAIN_CLASS_NAME" value="io.cucumber.core.cli.Main" />
<module name="rest" />
<option name="PROGRAM_PARAMETERS" value=" --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm5SMFormatter" />
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<properties>
<java.version>11</java.version>
<cucumber.version>6.8.0</cucumber.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -75,6 +76,25 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<!-- TESTING -->

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package de.filefighter.rest.domain.permission.data.dto;

import de.filefighter.rest.domain.user.data.dto.User;
import de.filefighter.rest.domain.user.role.Role;
import de.filefighter.rest.domain.user.role.Groups;
import lombok.Getter;

@Getter
public class PermissionSet {
private final Role[] visibleForRoles;
private final Role[] editableForRoles;
private final Groups[] visibleForRoles;
private final Groups[] editableForRoles;
private final User[] visibleForUsers;
private final User[] editableForUsers;

public PermissionSet(Role[] visibleForRoles, Role[] editableForRoles, User[] visibleForUsers, User[] editableForUsers) {
public PermissionSet(Groups[] visibleForRoles, Groups[] editableForRoles, User[] visibleForUsers, User[] editableForUsers) {
this.visibleForRoles = visibleForRoles;
this.editableForRoles = editableForRoles;
this.visibleForUsers = visibleForUsers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package de.filefighter.rest.domain.user.data.dto;
import de.filefighter.rest.domain.user.role.Role;
import de.filefighter.rest.domain.user.role.Groups;
import lombok.Builder;
import lombok.Data;

Expand All @@ -9,9 +9,9 @@
public class User {
private long id;
private String username;
private Role[] roles;
private Groups[] roles;

public User(long id, String username, Role... roles) {
public User(long id, String username, Groups... roles) {
this.id = id;
this.username = username;
this.roles = roles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
import org.springframework.stereotype.Service;

@Service
public class RoleRepository {
private final Role[] roles = Role.values();
public class GroupRepository {
private final Groups[] roles = Groups.values();

//TODO: test this.
public Role getRoleById(long id) {
for (Role role : roles) {
public Groups getRoleById(long id) {
for (Groups role : roles) {
if (role.getRoleId() == id) {
return role;
}
}
throw new IllegalArgumentException("id doesnt belong to a role");
}

public Role[] getRolesByIds(long... ids){
Role[] roles = new Role[ids.length]; //TODO: check this again.
public Groups[] getRolesByIds(long... ids){
Groups[] roles = new Groups[ids.length]; //TODO: check this again.

for (int i = 0; i < ids.length; i++) {
roles[i] = this.getRoleById(ids[i]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package de.filefighter.rest.domain.user.role;

public enum Role {
public enum Groups {
UNDEFINED(-1, "No group"),
FAMILY(0, "Family"),
ADMIN(1, "Admin");

private final long roleId;
private final String displayName;

Role(long roleId, String displayName) {
Groups(long roleId, String displayName) {
this.roleId = roleId;
this.displayName = displayName;
}
Expand Down
52 changes: 52 additions & 0 deletions src/test/cucumber/de/filefighter/rest/ViewFolderContents.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Feature: View Folder
As a user
I want to see the content of folders and navigate in them, so they can see and interact with their uploaded and shared files.

Background:
Given database is empty
And user 1234 exists
And user 1234 has access token "900000"
And "folder" exists with id 42 and path "bla"
And "file" exists with id 72 and path "bla/wow.txt"


Scenario: Successful interaction
Given user 1234 has permission of "view" for "folder" with id 42
And user 1234 has permission of "view" for "file" with id 72
When user with token "900000" wants to see the content of folder with path "bla"
Then response status code is 200
And the response contains the file with id 72 and name "wow.txt"


Scenario: Folder does not exist
Given user 1234 has permission of "view" for "folder" with id 42
When user with token "900000" wants to see the content of folder with path "bla/fasel"
Then response status code is 400
And response message contains "Folder does not exist, or you are not allowed to see the folder."


Scenario: insufficient authorization
Given user 9877 exists
And user 9877 has access token "2345678"
When user with token "2345678" wants to see the content of folder with path "bla"
Then response status code is 400
And response message contains "Folder does not exist, or you are not allowed to see the folder."

Scenario: shared file
Given "folder" exists with id 43 and path "bla"
And "file" exists with id 73 and path "bla/wow.txt"
And user 1234 is owner of file or folder with id 42
And user 1234 is owner of file or folder with id 72
And user 1234 has permission of "view" for "folder" with id 43
And user 1234 has permission of "view" for "file" with id 73
When user with token "900000" wants to see the content of folder with path "bla"
Then response status code is 200
And the response contains the file with id 72 and name "wow.txt"
And the response contains the file with id 73 and name "wow.txt"

Scenario: empty directory
Given "folder" exists with id 44 and path "empty"
And user 1234 has permission of "view" for "folder" with id 44
When user with token "900000" wants to see the content of folder with path "empty"
Then response status code is 200
And the response contains an empty list for files and folders
98 changes: 98 additions & 0 deletions src/test/cucumber/de/filefighter/rest/crudPermissions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Feature: CRUD Permissions
As a user and owner a file
I want want to be able to give or revoke other users permissions to either see or see and edit certain files or folders, so they can work together on the same files


Background:
Given database is empty
And user 1234 exists
And user 9877 exists
And user 1234 has access token "900000"
And user 9877 has access token "2345678"


Scenario Outline: Successful interaction for changing existing permission
Given "<type>" exists with id <id> and path "<path>"
And user 1234 is owner of file or folder with id <id>
And user 9877 has permission of "<old_permission>" for "<type>" with id <id>
When user with token "900000" wants to change permissions of "<type>" with id <id> for user with id 9877 to "<new_permission>"
Then response status code is <status_code>
And user 9877 has permission of "<new_permission>" for "<type>" with id <id>
Examples:
| type | id | path | old_permission | new_permission | status_code |
| file | 12 | bar.txt | edit | view | 200 |
| folder | 11 | f | edit | view | 200 |
| folder | 11 | f | view | edit | 200 |
| folder | 11 | f | view | view | 304 |
| file | 11 | f.txt | edit | edit | 304 |


Scenario Outline: Successful interaction for removing existing permission
Given "<type>" exists with id <id> and path "<path>"
And user 1234 is owner of file or folder with id <id>
And user 9877 has permission of "<old_permission>" for "<type>" with id <id>
When user with token "900000" wants to remove permissions of "<type>" with id <id> for user 9877
Then response status code is <status_code>
And user with id 9877 has no permission for "<type>" with id <id>
Examples:
| type | id | path | old_permission | status_code |
| file | 12 | fo.c | view | 200 |
| folder | 11 | f | view | 200 |
| file | 10 | f.c | edit | 200 |
| folder | 10 | fc | edit | 200 |


Scenario: removing not existing permission
Given "file" exists with id 111 and path "bla.txt"
And user 1234 is owner of file or folder with id 111
And user 9877 has no permission for "file" with id 111
When user with token "900000" wants to remove permissions of "file" with id 111 for user 9877
Then response status code is 400
Then response message contains "Couldn't remove permission that does not exit."


Scenario Outline: Successful interaction adding new permission
Given "<type>" exists with id <id> and path "<path>"
And user 1234 is owner of file or folder with id <id>
And user 9877 has no permission for "<type>" with id <id>
When user with token "900000" wants to add permissions of "<type>" with id <id> for user 9877 for "<new_permission>"
Then response status code is 200
And user 9877 has permission of "<new_permission>" for "<type>" with id <id>
Examples:
| type | id | path | new_permission |
| file | 12 | f.c | edit |
| file | 12 | f.c | view |
| folder | 21 | f | edit |
| folder | 22 | fd | view |


Scenario: User is not owner of file
Given "file" exists with id 111 and path "bla.txt"
And user 3131 exists
And user 9877 is owner of file or folder with id 111
When user with token "900000" wants to add permissions of "file" with id 111 for user 3131 for "edit"
Then response status code is 403
And response message contains "User with id 1234 is not owner of file with id 111."


Scenario: User does not exist
Given "file" exists with id 111 and path "bla.txt"
And user 1234 is owner of file or folder with id 111
When user with token "900000" wants to add permissions of "file" with id 111 for user 3131 for "edit"
Then response status code is 404
And response message contains "User 3131 does not exist."


Scenario: File does not exist
And user 1234 is owner of file or folder with id 111
When user with token "900000" wants to add permissions of "file" with id 111 for user 9877 for "edit"
Then response status code is 404
And response message contains "No File with id 111 found."


Scenario: User is already owner
Given "file" exists with id 111 and path "bla.txt"
And user 1234 is owner of file or folder with id 111
When user with token "900000" wants to add permissions of "file" with id 111 for user 1234 for "edit"
Then response status code is 405
And response message contains "User with id 1234 is already owner of file with id 111."
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package de.filefighter.rest.cucumber;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class CrudPermissionSteps extends SpringIntegrationTest{

// TODO: Rearrange the steps, create Shared State Handler.

@Given("database is empty")
public void databaseIsEmpty() {
}

@And("user {int} exists")
public void userExists(int arg0) {
}

@And("user {int} has access token {string}")
public void userHasAccessToken(int arg0, String arg1) {
}

@And("user {int} has permission of {string} for {string} with id {int}")
public void userHasPermissionOfForWithIdId(int arg0, String arg1, String arg2,int arg3) {
}

@When("user with token {string} wants to change permissions of {string} with id {int} for user with id {int} to {string}")
public void userWithTokenWantsToChangePermissionsOfWithIdIdForUserWithIdTo(String arg0, String arg1, int fileID,int arg2, String arg3) {
}

@When("user with token {string} wants to remove permissions of {string} with id {int} for user {int}")
public void userWithTokenWantsToRemovePermissionsOfWithIdIdForUser(String arg0, String arg1,int fileID, int arg2) {
}

@And("user with id {int} has no permission for {string} with id {int}")
public void userWithIdHasNoPermissionForWithIdId(int arg0, String arg1, int fileID) {
}

@Given("{string} exists with id {int} and path {string}")
public void existsWithIdAndPath(String arg0, int arg1, String arg2) {
}

@And("user {int} is owner of file or folder with id {int}")
public void userIsOwnerOfFileOrFolderWithId(int arg0, int arg1) {
}

@And("user {int} has no permission for {string} with id {int}")
public void userHasNoPermissionForWithId(int arg0, String arg1, int arg2) {
}

@Then("response status code is {int}")
public void responseStatusCodeIs(int arg0) {
}

@Then("response message contains {string}")
public void responseMessageContains(String arg0) {
}

@When("user with token {string} wants to add permissions of {string} with id {int} for user {int} for {string}")
public void userWithTokenWantsToAddPermissionsOfWithIdForUserFor(String arg0, String arg1, int arg2, int arg3, String arg4) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package de.filefighter.rest.cucumber;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/cucumber/de/filefighter/rest/")
public class CucumberIntegrationTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.filefighter.rest.cucumber;

import io.cucumber.spring.CucumberContextConfiguration;
import org.springframework.boot.test.context.SpringBootTest;

@CucumberContextConfiguration
@SpringBootTest
public class SpringIntegrationTest {
}
Loading