Commit a2d18870 authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'create-deploy-token-resource-api' into 'master'

Fabricate project deploy token resource via API

See merge request gitlab-org/gitlab!74901
parents e62256ab a4082b26
......@@ -2,31 +2,48 @@
module QA
module Resource
class DeployToken < Base
class ProjectDeployToken < Base
attr_accessor :name, :expires_at
attr_writer :scopes
attribute :username do
Page::Project::Settings::Repository.perform do |repository_page|
repository_page.expand_deploy_tokens do |token|
token.token_username
attribute :id
attribute :token
attribute :username
attribute :project do
Project.fabricate! do |resource|
resource.name = 'project-to-deploy'
resource.description = 'project for adding deploy token test'
end
end
def fabricate_via_api!
super
end
attribute :password do
Page::Project::Settings::Repository.perform do |repository_page|
repository_page.expand_deploy_tokens do |token|
token.token_password
def api_get_path
"/projects/#{project.id}/deploy_tokens"
end
def api_post_path
api_get_path
end
def api_post_body
{
name: @name,
scopes: @scopes
}
end
attribute :project do
Project.fabricate! do |resource|
resource.name = 'project-to-deploy'
resource.description = 'project for adding deploy token test'
def api_delete_path
"/projects/#{project.id}/deploy_tokens/#{id}"
end
def resource_web_url(resource)
super
rescue ResourceURLMissingError
# this particular resource does not expose a web_url property
end
def fabricate!
......
......@@ -14,15 +14,15 @@ module QA
end
let(:project_deploy_token) do
Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token|
Resource::ProjectDeployToken.fabricate_via_api! do |deploy_token|
deploy_token.name = 'registry-deploy-token'
deploy_token.project = project
deploy_token.scopes = [
:read_repository,
:read_package_registry,
:write_package_registry,
:read_registry,
:write_registry
deploy_token.scopes = %w[
read_repository
read_package_registry
write_package_registry
read_registry
write_registry
]
end
end
......@@ -60,7 +60,7 @@ module QA
when :personal_access_token
"\"#{personal_access_token}\""
when :project_deploy_token
"\"#{project_deploy_token.password}\""
"\"#{project_deploy_token.token}\""
when :ci_job_token
'$CI_JOB_TOKEN'
end
......
......@@ -88,7 +88,7 @@ module QA
when :ci_job_token
'${CI_JOB_TOKEN}'
when :project_deploy_token
project_deploy_token.password
project_deploy_token.token
end
end
......
......@@ -97,7 +97,7 @@ module QA
when :ci_job_token
'System.getenv("CI_JOB_TOKEN")'
when :project_deploy_token
"\"#{project_deploy_token.password}\""
"\"#{project_deploy_token.token}\""
end
end
......
......@@ -142,7 +142,7 @@ module QA
when :ci_job_token
'${env.CI_JOB_TOKEN}'
when :project_deploy_token
project_deploy_token.password
project_deploy_token.token
end
end
......
......@@ -16,13 +16,13 @@ module QA
end
let(:project_deploy_token) do
Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token|
Resource::ProjectDeployToken.fabricate_via_api! do |deploy_token|
deploy_token.name = 'npm-deploy-token'
deploy_token.project = project
deploy_token.scopes = [
:read_repository,
:read_package_registry,
:write_package_registry
deploy_token.scopes = %w[
read_repository
read_package_registry
write_package_registry
]
end
end
......@@ -151,7 +151,7 @@ module QA
when :ci_job_token
'${CI_JOB_TOKEN}'
when :project_deploy_token
"\"#{project_deploy_token.password}\""
"\"#{project_deploy_token.token}\""
end
end
......
......@@ -16,13 +16,13 @@ module QA
end
let(:project_deploy_token) do
Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token|
Resource::ProjectDeployToken.fabricate_via_api! do |deploy_token|
deploy_token.name = 'npm-deploy-token'
deploy_token.project = project
deploy_token.scopes = [
:read_repository,
:read_package_registry,
:write_package_registry
deploy_token.scopes = %w[
read_repository
read_package_registry
write_package_registry
]
end
end
......@@ -129,7 +129,7 @@ module QA
when :ci_job_token
'${CI_JOB_TOKEN}'
when :project_deploy_token
"\"#{project_deploy_token.password}\""
"\"#{project_deploy_token.token}\""
end
end
......
......@@ -9,14 +9,14 @@ module QA
deploy_token_name = 'deploy token name'
one_week_from_now = Date.today + 7
deploy_token = Resource::DeployToken.fabricate_via_browser_ui! do |resource|
deploy_token = Resource::ProjectDeployToken.fabricate_via_api! do |resource|
resource.name = deploy_token_name
resource.expires_at = one_week_from_now
resource.scopes = [:read_repository]
resource.scopes = %w[read_repository]
end
expect(deploy_token.username.length).to be > 0
expect(deploy_token.password.length).to be > 0
expect(deploy_token.token.length).to be > 0
end
end
end
......
......@@ -42,13 +42,13 @@ module QA
end
let(:project_deploy_token) do
Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token|
Resource::ProjectDeployToken.fabricate_via_api! do |deploy_token|
deploy_token.name = 'package-deploy-token'
deploy_token.project = package_project
deploy_token.scopes = [
:read_repository,
:read_package_registry,
:write_package_registry
deploy_token.scopes = %w[
read_repository
read_package_registry
write_package_registry
]
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment