Skip to content

Commit

Permalink
release v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
contabo committed Feb 16, 2022
1 parent 61fab14 commit 8048434
Show file tree
Hide file tree
Showing 89 changed files with 1,843 additions and 1,092 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dist/
openapi/
.DS_Store
.vscode
.idea
.idea
rechnung*
153 changes: 141 additions & 12 deletions bats/create_role.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,171 @@ function teardown_file() {
}


@test "create role api permission: ok" {
run ./cntb create role apiPermission --name="foo${TEST_SUFFIX}" --apiPermission='[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
@test "create role without resources : ok" {
run ./cntb create role --name "foo${TEST_SUFFIX}" --permissions '[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
assert_success
roleId="$output"

run ./cntb get role $roleId -o yaml
assert_success
assert_output --partial 'admin: false'
assert_output --partial 'accessAllResources: false'

# clean up
run ./cntb delete role "${roleId}"
assert_success
}

@test "create role with admin : ok" {
run ./cntb create role --name "foo${TEST_SUFFIX}" --admin
assert_success
roleId="$output"

run ./cntb get role $roleId -o yaml
assert_success
assert_output --partial 'admin: true'

# clean up
run ./cntb delete role "${roleId}"
assert_success
}

@test "create role with accessAllResources : ok" {
run ./cntb create role --name "foo${TEST_SUFFIX}" -p '[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]' --accessAllResources
assert_success
roleId="$output"

run ./cntb get role $roleId -o yaml
assert_success
assert_output --partial 'accessAllResources: true'

# clean up
run ./cntb delete role apiPermission "${roleId}"
run ./cntb delete role "${roleId}"
assert_success
}


@test "create role wrong permission type: nok" {
run ./cntb create role aa --name="foo${TEST_SUFFIX}" --apiPermission='[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
@test "create role without resources short flags : ok" {
run ./cntb create role -n "foo${TEST_SUFFIX}" -p '[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
assert_success
roleId="$output"

# clean up
run ./cntb delete role "${roleId}"
assert_success
}

@test "create role without resources multiple endpoints : ok" {
run ./cntb create role --name "foo${TEST_SUFFIX}" --permissions '[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}, {"apiName":"/v1/tags","actions":["READ"]}]'
assert_success
roleId="$output"

# clean up
run ./cntb delete role "${roleId}"
assert_success
}

@test "create role with resources : ok" {
run ./cntb create tag --name "foo${TEST_SUFFIX}"
assert_success
tagid="$output"

run ./cntb create role --name "foo${TEST_SUFFIX}" --permissions "[{\"apiName\" : \"/v1/users\", \"actions\": [\"READ\", \"CREATE\"], \"resources\": [$tagid]}]"
assert_success
roleId="$output"

# clean up
run ./cntb delete role "${roleId}"
assert_success
}

@test "create role with resources multiple endpoints : ok" {
run ./cntb create tag --name "foo${TEST_SUFFIX}"
assert_success
tagid="$output"

run ./cntb create role --name "foo${TEST_SUFFIX}" --permissions "[{\"apiName\" : \"/v1/users\", \"actions\": [\"READ\", \"CREATE\"], \"resources\": [$tagid]}, {\"apiName\":\"/v1/tags\",\"actions\":[\"READ\"], \"resources\": [$tagid]}]"
assert_success
roleId="$output"

# clean up
run ./cntb delete role "${roleId}"
assert_success
}


@test "create role with resources multiple endpoints only one with tag : ok" {
run ./cntb create tag --name "foo${TEST_SUFFIX}"
assert_success
tagid="$output"

run ./cntb create role --name "foo${TEST_SUFFIX}" --permissions "[{\"apiName\" : \"/v1/users\", \"actions\": [\"READ\", \"CREATE\"], \"resources\": [$tagid]},{\"apiName\":\"/v1/tags\",\"actions\":[\"READ\"]}]"
assert_success
roleId="$output"

run ./cntb get role $roleId -o yaml
assert_success
assert_output --partial 'admin: false'
assert_output --partial 'accessAllResources: false'

# clean up
run ./cntb delete role "${roleId}"
assert_success
}

@test "create role with foreign tagId : nok : check error" {
run ./cntb create --name "foo${TEST_SUFFIX}" role --permissions '[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"], "resources": [0]}]'
assert_failure
assert_output --partial 'not found'
assert_output --partial '404'
}

@test "create role without name : nok" {
run ./cntb create role --permissions '[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
assert_failure
}

@test "create role wrong number of inputs: nok" {
run ./cntb create role --name="foo${TEST_SUFFIX}" --apiPermission='[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
@test "create role without permissions : nok" {
run ./cntb create role --name="foo${TEST_SUFFIX}"
assert_failure
}

run .run ./cntb create role apiPermission apiPermission --name="foo${TEST_SUFFIX}" --apiPermission='[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
@test "create role without name and permissions: nok" {
run ./cntb create role
assert_failure
}

@test "create role with wrong action in permissions : nok" {
run ./cntb create role -n foo${TEST_SUFFIX} --permissions '[{"apiName": "/v1/tags", "actions": ["UNKNOWN"]}]'
assert_failure
}

@test "create role with unknown api endpoint : nok" {
run ./cntb create role -n foo${TEST_SUFFIX} --permissions '[{"apiName": "/unkown/api/endpoint", "actions": ["CREATE"]}]'
assert_failure
}

@test "create role with wrong JSON permissions : nok" {
run ./cntb create role -n foo${TEST_SUFFIX} --permissions '["apiName": "/unkown/api/endpoint", "actions": ["CREATE"]}]'
assert_failure
}


wrapperCreateApiPermissionFile() {
echo "$1" | ./cntb create role apiPermission -f -
echo "$1" | ./cntb create role -f -
}

@test "create from file api permission: ok" {
run wrapperCreateApiPermissionFile '{"name": "foo", "apiPermissions": [{"apiName": "/v1/users", "actions": ["READ", "CREATE"]}]}'
@test "create from file api permission : ok" {
run wrapperCreateApiPermissionFile '{"name": "foo", "permissions": [{"apiName": "/v1/users", "actions": ["READ", "CREATE"], "resources": []}]}'
assert_success
roleId="$output"

# clean up
run ./cntb delete role apiPermission "$roleId"
run ./cntb delete role "$roleId"
assert_success
}

@test "create from file missing name : nok" {
run wrapperCreateApiPermissionFile '{"permissions": [{"apiName": "/v1/users", "actions": ["READ", "CREATE"]}]}'
assert_failure
}
49 changes: 39 additions & 10 deletions bats/create_user.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,86 @@ function teardown_file() {
restore_config_files
}
@test "create user normal: ok" {
run ./cntb create role apiPermission --name="foo${TEST_SUFFIX}" --apiPermission='[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
run ./cntb create role -n "foo${TEST_SUFFIX}" -p '[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
assert_success
roleId="$output"


run ./cntb create user --firstName="foo${TEST_SUFFIX}" --lastName="bar${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --admin=true --accessAllResources=true --roles="$roleId"
run ./cntb create user --firstName="foo${TEST_SUFFIX}" --lastName="bar${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --roles="$roleId" --locale de
assert_success
userId="$output"


#clean up
run ./cntb delete user "$userId"
assert_success
run ./cntb delete role apiPermission "$roleId"
run ./cntb delete role "$roleId"
assert_success
}

@test "create user duplicate: nok" {
run ./cntb create role apiPermission --name="foo${TEST_SUFFIX}" --apiPermission='[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
run ./cntb create role -n "foo${TEST_SUFFIX}" -p '[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
assert_success
roleId="$output"


run ./cntb create user --firstName="foo${TEST_SUFFIX}" --lastName="bar${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --admin=true --accessAllResources=true --roles="$roleId"
run ./cntb create user --firstName="foo${TEST_SUFFIX}" --lastName="bar${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --roles="$roleId" --locale de
assert_success
userId="$output"

run ./cntb create user --firstName="foo${TEST_SUFFIX}" --lastName="bar${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --admin=true --accessAllResources=true --roles="$roleId"
run ./cntb create user --firstName="foo${TEST_SUFFIX}" --lastName="bar${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --roles="$roleId" --locale de
assert_failure


#clean up
run ./cntb delete user "$userId"
assert_success
run ./cntb delete role apiPermission "$roleId"
run ./cntb delete role "$roleId"
assert_success
}


@test "create user missing e-mail: nok" {
run ./cntb create user --firstName="foo${TEST_SUFFIX}" --lastName="bar${TEST_SUFFIX}" --enabled=true --admin=true --accessAllResources=true --roles="$roleId"
run ./cntb create user --firstName="foo${TEST_SUFFIX}" --lastName="bar${TEST_SUFFIX}" --enabled=true --roles="$roleId" --locale de
assert_failure

export CNTB_FIRSTNAME="foo${TEST_SUFFIX}"
export CNTB_LASTNAME="bar${TEST_SUFFIX}"
export CNTB_ENABLED=true
export CNTB_LOCALE=de

run ./cntb create user
assert_failure

unset CNTB_FIRSTNAME CNTB_LASTNAME CNTB_ENABLED CNTB_LOCALE
}

@test "create user missing firstName: nok" {
run ./cntb create user --lastName="bar${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --admin=true --accessAllResources=true --roles="$roleId"
run ./cntb create user --lastName="bar${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --roles="$roleId" --locale de
assert_failure

export CNTB_LASTNAME="bar${TEST_SUFFIX}"
export CNTB_ENABLED=true
export CNTB_LOCALE=de
export CNTB_EMAIL="testuser${TEST_SUFFIX}@contabo.com"

run ./cntb create user
assert_failure

unset CNTB_EMAIL CNTB_LASTNAME CNTB_ENABLED CNTB_LOCALE
}

@test "create user missing lastName: nok" {
run ./cntb create user --firstName="foo${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --admin=true --accessAllResources=true --roles="$roleId"
run ./cntb create user --firstName="foo${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --roles="$roleId" --locale de
assert_failure

export CNTB_FIRSTNAME="foo${TEST_SUFFIX}"
export CNTB_ENABLED=true
export CNTB_LOCALE=de
export CNTB_EMAIL="testuser${TEST_SUFFIX}@contabo.com"

run ./cntb create user
assert_failure

unset CNTB_FIRSTNAME CNTB_EMAIL CNTB_ENABLED CNTB_LOCALE
}
35 changes: 18 additions & 17 deletions bats/delete_role.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,42 @@ function teardown_file() {
restore_config_files
}

@test "delete role ok:" {
run ./cntb create role apiPermission --name="foo${TEST_SUFFIX}" --apiPermission='[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
@test "delete role : ok" {
run ./cntb create role --name "foo${TEST_SUFFIX}" --permissions '[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
assert_success
roleId="$output"

run ./cntb delete role apiPermission "$roleId"
run ./cntb get role "$roleId"
assert_success

run ./cntb delete role "$roleId"
assert_success

run ./cntb get role apiPermission "$roleId"
run ./cntb get role "$roleId"
assert_failure
}

@test "delete not existing role" {
run ./cntb delete role apiPermission 0
@test "delete not existing role : nok" {
run ./cntb delete role 0
assert_failure
assert_output --partial "Error while deleting role: 404 - Entry Role not found by roleId"
}

@test "use wrong permission type: nok" {
run ./cntb delete role akdslfj 0
assert_failure
}

@test "use only 1 input: nok" {
run ./cntb delete role apiPermission
@test "delete without roleId : nok" {
run ./cntb delete role
assert_failure
}

@test "user more than 2 inputs: nok" {
run ./cntb delete role apiPermission 2 apiPermission
@test "delete with role type and roleId : nok" {
run ./cntb delete role apiPermission 2
assert_failure
}
@test "delete with roleId and role type : nok" {
run ./cntb delete role 2 apiPermission
assert_failure
}

@test "user string instead of number for role id" {
run ./cntb delete role apiPermission test
@test "user string instead of number for role id : nok" {
run ./cntb delete role twelve
assert_failure
}
6 changes: 3 additions & 3 deletions bats/delete_user.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ function teardown_file() {
}

@test "delete user ok" {
run ./cntb create role apiPermission --name="foo${TEST_SUFFIX}" --apiPermission='[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
run ./cntb create role -n "foo${TEST_SUFFIX}" -p '[{"apiName" : "/v1/users", "actions": ["READ", "CREATE"]}]'
assert_success
roleId="$output"

run ./cntb create user --firstName="foo${TEST_SUFFIX}" --lastName="bar${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --admin=true --accessAllResources=true --roles="$roleId"
run ./cntb create user --firstName="foo${TEST_SUFFIX}" --lastName="bar${TEST_SUFFIX}" --email="testuser${TEST_SUFFIX}@contabo.com" --enabled=true --roles="$roleId" --locale de
assert_success
userId="$output"

run ./cntb delete user "${userId}"
assert_success

#cleanup
run ./cntb delete role apiPermission "${roleId}"
run ./cntb delete role "${roleId}"
assert_success

}
Expand Down
Loading

0 comments on commit 8048434

Please sign in to comment.