summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorayoub mrini <amrini@wiremind.fr>2020-03-19 23:30:40 +0100
committerayoub mrini <amrini@wiremind.fr>2020-04-06 20:52:35 +0200
commit01de524ce39a67b549b3157bf4de827dd0568d6b (patch)
treee195869989b88b998ab0452ac8572c02895db396 /tools
parentc5904c4c2e79ec302ff0de20bcb2792be4924bbe (diff)
downloadgitlab-01de524ce39a67b549b3157bf4de827dd0568d6b.tar.gz
feat(api): add support for Gitlab Deploy Token API
Diffstat (limited to 'tools')
-rwxr-xr-xtools/cli_test_v4.sh88
-rw-r--r--tools/python_test_v4.py50
2 files changed, 130 insertions, 8 deletions
diff --git a/tools/cli_test_v4.sh b/tools/cli_test_v4.sh
index b916705..395289a 100755
--- a/tools/cli_test_v4.sh
+++ b/tools/cli_test_v4.sh
@@ -195,14 +195,6 @@ testcase "project upload" '
--filename '$(basename $0)' --filepath '$0' >/dev/null 2>&1
'
-testcase "project deletion" '
- GITLAB project delete --id "$PROJECT_ID"
-'
-
-testcase "group deletion" '
- OUTPUT=$(try GITLAB group delete --id $GROUP_ID)
-'
-
testcase "application settings get" '
GITLAB application-settings get >/dev/null 2>&1
'
@@ -222,3 +214,83 @@ testcase "values from files" '
echo $OUTPUT | grep -q "Multi line"
'
+# Test deploy tokens
+CREATE_PROJECT_DEPLOY_TOKEN_OUTPUT=$(GITLAB -v project-deploy-token create --project-id $PROJECT_ID \
+ --name foo --username root --expires-at "2021-09-09" --scopes "read_registry")
+CREATED_DEPLOY_TOKEN_ID=$(echo "$CREATE_PROJECT_DEPLOY_TOKEN_OUTPUT" | grep ^id: | cut -d" " -f2)
+testcase "create project deploy token" '
+ echo $CREATE_PROJECT_DEPLOY_TOKEN_OUTPUT | grep -q "name: foo"
+'
+testcase "create project deploy token" '
+ echo $CREATE_PROJECT_DEPLOY_TOKEN_OUTPUT | grep -q "expires-at: 2021-09-09T00:00:00.000Z"
+'
+testcase "create project deploy token" '
+ echo $CREATE_PROJECT_DEPLOY_TOKEN_OUTPUT | grep "scopes: " | grep -q "read_registry"
+'
+# Uncomment once https://gitlab.com/gitlab-org/gitlab/-/issues/211963 is fixed
+#testcase "create project deploy token" '
+# echo $CREATE_PROJECT_DEPLOY_TOKEN_OUTPUT | grep -q "username: root"
+#'
+
+# Remove once https://gitlab.com/gitlab-org/gitlab/-/issues/211963 is fixed
+testcase "create project deploy token" '
+ echo $CREATE_PROJECT_DEPLOY_TOKEN_OUTPUT | grep -q "gitlab+deploy-token"
+'
+
+LIST_DEPLOY_TOKEN_OUTPUT=$(GITLAB -v deploy-token list)
+testcase "list all deploy tokens" '
+ echo $LIST_DEPLOY_TOKEN_OUTPUT | grep -q "name: foo"
+'
+testcase "list all deploy tokens" '
+ echo $LIST_DEPLOY_TOKEN_OUTPUT | grep -q "id: $CREATED_DEPLOY_TOKEN_ID"
+'
+testcase "list all deploy tokens" '
+ echo $LIST_DEPLOY_TOKEN_OUTPUT | grep -q "expires-at: 2021-09-09T00:00:00.000Z"
+'
+testcase "list all deploy tokens" '
+ echo $LIST_DEPLOY_TOKEN_OUTPUT | grep "scopes: " | grep -q "read_registry"
+'
+
+testcase "list project deploy tokens" '
+ OUTPUT=$(GITLAB -v project-deploy-token list --project-id $PROJECT_ID)
+ echo $OUTPUT | grep -q "id: $CREATED_DEPLOY_TOKEN_ID"
+'
+testcase "delete project deploy token" '
+ GITLAB -v project-deploy-token delete --project-id $PROJECT_ID --id $CREATED_DEPLOY_TOKEN_ID
+ LIST_PROJECT_DEPLOY_TOKEN_OUTPUT=$(GITLAB -v project-deploy-token list --project-id $PROJECT_ID)
+ echo $LIST_PROJECT_DEPLOY_TOKEN_OUTPUT | grep -qv "id: $CREATED_DEPLOY_TOKEN_ID"
+'
+# Uncomment once https://gitlab.com/gitlab-org/gitlab/-/issues/212523 is fixed
+#testcase "delete project deploy token" '
+# LIST_DEPLOY_TOKEN_OUTPUT=$(GITLAB -v deploy-token list)
+# echo $LIST_DEPLOY_TOKEN_OUTPUT | grep -qv "id: $CREATED_DEPLOY_TOKEN_ID"
+#'
+
+CREATE_GROUP_DEPLOY_TOKEN_OUTPUT=$(GITLAB -v group-deploy-token create --group-id $GROUP_ID \
+ --name bar --username root --expires-at "2021-09-09" --scopes "read_repository")
+CREATED_DEPLOY_TOKEN_ID=$(echo "$CREATE_GROUP_DEPLOY_TOKEN_OUTPUT" | grep ^id: | cut -d" " -f2)
+testcase "create group deploy token" '
+ echo $CREATE_GROUP_DEPLOY_TOKEN_OUTPUT | grep -q "name: bar"
+'
+testcase "list group deploy tokens" '
+ OUTPUT=$(GITLAB -v group-deploy-token list --group-id $GROUP_ID)
+ echo $OUTPUT | grep -q "id: $CREATED_DEPLOY_TOKEN_ID"
+'
+testcase "delete group deploy token" '
+ GITLAB -v group-deploy-token delete --group-id $GROUP_ID --id $CREATED_DEPLOY_TOKEN_ID
+ LIST_GROUP_DEPLOY_TOKEN_OUTPUT=$(GITLAB -v group-deploy-token list --group-id $GROUP_ID)
+ echo $LIST_GROUP_DEPLOY_TOKEN_OUTPUT | grep -qv "id: $CREATED_DEPLOY_TOKEN_ID"
+'
+# Uncomment once https://gitlab.com/gitlab-org/gitlab/-/issues/212523 is fixed
+#testcase "delete group deploy token" '
+# LIST_DEPLOY_TOKEN_OUTPUT=$(GITLAB -v deploy-token list)
+# echo $LIST_DEPLOY_TOKEN_OUTPUT | grep -qv "id: $CREATED_DEPLOY_TOKEN_ID"
+#'
+
+testcase "project deletion" '
+ GITLAB project delete --id "$PROJECT_ID"
+'
+
+testcase "group deletion" '
+ OUTPUT=$(try GITLAB group delete --id $GROUP_ID)
+'
diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py
index 69b0d31..58ef081 100644
--- a/tools/python_test_v4.py
+++ b/tools/python_test_v4.py
@@ -625,6 +625,56 @@ assert len(sudo_project.keys.list()) == 1
sudo_project.keys.delete(deploy_key.id)
assert len(sudo_project.keys.list()) == 0
+# deploy tokens
+deploy_token = admin_project.deploytokens.create(
+ {
+ "name": "foo",
+ "username": "bar",
+ "expires_at": "2022-01-01",
+ "scopes": ["read_registry"],
+ }
+)
+assert len(admin_project.deploytokens.list()) == 1
+assert gl.deploytokens.list() == admin_project.deploytokens.list()
+
+assert admin_project.deploytokens.list()[0].name == "foo"
+assert admin_project.deploytokens.list()[0].expires_at == "2022-01-01T00:00:00.000Z"
+assert admin_project.deploytokens.list()[0].scopes == ["read_registry"]
+# Uncomment once https://gitlab.com/gitlab-org/gitlab/-/issues/211963 is fixed
+# assert admin_project.deploytokens.list()[0].username == "bar"
+deploy_token.delete()
+assert len(admin_project.deploytokens.list()) == 0
+# Uncomment once https://gitlab.com/gitlab-org/gitlab/-/issues/212523 is fixed
+# assert len(gl.deploytokens.list()) == 0
+
+
+deploy_token_group = gl.groups.create(
+ {"name": "deploy_token_group", "path": "deploy_token_group"}
+)
+
+# Uncomment once https://gitlab.com/gitlab-org/gitlab/-/issues/211878 is fixed
+# deploy_token = group_deploy_token.deploytokens.create(
+# {
+# "name": "foo",
+# "scopes": ["read_registry"],
+# }
+# )
+
+# Remove once https://gitlab.com/gitlab-org/gitlab/-/issues/211878 is fixed
+deploy_token = deploy_token_group.deploytokens.create(
+ {"name": "foo", "username": "", "expires_at": "", "scopes": ["read_repository"],}
+)
+
+assert len(deploy_token_group.deploytokens.list()) == 1
+# Uncomment once https://gitlab.com/gitlab-org/gitlab/-/issues/212523 is fixed
+# assert gl.deploytokens.list() == deploy_token_group.deploytokens.list()
+deploy_token.delete()
+assert len(deploy_token_group.deploytokens.list()) == 0
+# Uncomment once https://gitlab.com/gitlab-org/gitlab/-/issues/212523 is fixed
+# assert len(gl.deploytokens.list()) == 0
+
+deploy_token_group.delete()
+
# labels
# label1 = admin_project.labels.create({"name": "label1", "color": "#778899"})
# label1 = admin_project.labels.list()[0]