Commit fe09606a authored by Sofia Vistas's avatar Sofia Vistas

Merge branch 'refactor-nuget-test-auth-tokens' into 'master'

Refactor nuget to use supported auth tokens

See merge request gitlab-org/gitlab!68272
parents 441741f2 ed1493af
......@@ -68,8 +68,25 @@ module QA
end
end
def go_to_repository_settings
hover_group_settings do
within_submenu do
click_element(:sidebar_menu_item_link, menu_item: 'Repository')
end
end
end
private
def hover_settings
within_sidebar do
scroll_to_element(:sidebar_menu_link, menu_item: 'Settings')
find_element(:sidebar_menu_link, menu_item: 'Settings').hover
yield
end
end
def hover_issues
within_sidebar do
scroll_to_element(:sidebar_menu_link, menu_item: 'Issues')
......
# frozen_string_literal: true
module QA
module Page
module Group
module Settings
class GroupDeployTokens < Page::Base
view 'app/views/shared/deploy_tokens/_form.html.haml' do
element :deploy_token_name_field
element :deploy_token_expires_at_field
element :deploy_token_read_repository_checkbox
element :deploy_token_read_package_registry_checkbox
element :deploy_token_read_registry_checkbox
element :deploy_token_write_package_registry_checkbox
element :create_deploy_token_button
end
view 'app/views/shared/deploy_tokens/_new_deploy_token.html.haml' do
element :created_deploy_token_container
element :deploy_token_user_field
element :deploy_token_field
end
def fill_token_name(name)
fill_element(:deploy_token_name_field, name)
end
def fill_token_expires_at(expires_at)
fill_element(:deploy_token_expires_at_field, expires_at.to_s + "\n")
end
def fill_scopes(read_repository: false, read_registry: false, read_package_registry: false, write_package_registry: false )
check_element(:deploy_token_read_repository_checkbox) if read_repository
check_element(:deploy_token_read_package_registry_checkbox) if read_package_registry
check_element(:deploy_token_read_registry_checkbox) if read_registry
check_element(:deploy_token_write_package_registry_checkbox) if write_package_registry
end
def add_token
click_element(:create_deploy_token_button)
end
def token_username
within_new_project_deploy_token do
find_element(:deploy_token_user_field).value
end
end
def token_password
within_new_project_deploy_token do
find_element(:deploy_token_field).value
end
end
private
def within_new_project_deploy_token
has_element?(:created_deploy_token_container, wait: QA::Support::Repeater::DEFAULT_MAX_WAIT_TIME)
within_element(:created_deploy_token_container) do
yield
end
end
end
end
end
end
end
# frozen_string_literal: true
module QA
module Page
module Group
module Settings
class Repository < Page::Base
include QA::Page::Settings::Common
view 'app/views/shared/deploy_tokens/_index.html.haml' do
element :deploy_tokens_settings_content
end
def expand_deploy_tokens(&block)
expand_content(:deploy_tokens_settings_content) do
Settings::GroupDeployTokens.perform(&block)
end
end
end
end
end
end
end
# frozen_string_literal: true
module QA
module Resource
class GroupDeployToken < Base
attr_accessor :name, :expires_at
attribute :username do
Page::Group::Settings::Repository.perform do |repository_page|
repository_page.expand_deploy_tokens(&:token_username)
end
end
attribute :password do
Page::Group::Settings::Repository.perform do |repository_page|
repository_page.expand_deploy_tokens(&:token_password)
end
end
attribute :group do
Group.fabricate! do |resource|
resource.name = 'group-with-deploy-token'
resource.description = 'group for adding deploy token test'
end
end
attribute :project do
Project.fabricate! do |resource|
resource.name = 'project-to-deploy'
resource.description = 'project for adding deploy token test'
end
end
def fabricate!
group.visit!
Page::Group::Menu.perform(&:go_to_repository_settings)
Page::Group::Settings::Repository.perform do |setting|
setting.expand_deploy_tokens do |page|
page.fill_token_name(name)
page.fill_token_expires_at(expires_at)
page.fill_scopes(read_repository: true, read_package_registry: true, write_package_registry: true)
page.add_token
end
end
end
end
end
end
......@@ -3,6 +3,7 @@
module QA
RSpec.describe 'Package', :orchestrated, :packages, :object_storage do
describe 'NuGet Repository' do
using RSpec::Parameterized::TableSyntax
include Runtime::Fixtures
let(:project) do
Resource::Project.fabricate_via_api! do |project|
......@@ -11,6 +12,21 @@ module QA
end
end
let(:personal_access_token) do
unless Page::Main::Menu.perform(&:signed_in?)
Flow::Login.sign_in
end
Resource::PersonalAccessToken.fabricate!
end
let(:group_deploy_token) do
Resource::GroupDeployToken.fabricate_via_browser_ui! do |deploy_token|
deploy_token.name = 'nuget-group-deploy-token'
deploy_token.group = project.group
end
end
let(:package) do
Resource::Package.init do |package|
package.name = "dotnetcore-#{SecureRandom.hex(8)}"
......@@ -40,7 +56,36 @@ module QA
package.remove_via_api!
end
it 'publishes a nuget package at the project level, installs and deletes it at the group level', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1641' do
where(:authentication_token_type, :token_name) do
:personal_access_token | 'Personal Access Token'
:ci_job_token | 'CI Job Token'
:group_deploy_token | 'Deploy Token'
end
with_them do
let(:auth_token_password) do
case authentication_token_type
when :personal_access_token
"\"#{personal_access_token.token}\""
when :ci_job_token
'${CI_JOB_TOKEN}'
when :group_deploy_token
"\"#{group_deploy_token.password}\""
end
end
let(:auth_token_username) do
case authentication_token_type
when :personal_access_token
"\"#{personal_access_token.user.username}\""
when :ci_job_token
'gitlab-ci-token'
when :group_deploy_token
"\"#{group_deploy_token.username}\""
end
end
it "publishes a nuget package at the project level, installs and deletes it at the group level using a #{params[:token_name]}", testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1073' do
Flow::Login.sign_in
Resource::Repository::Commit.fabricate_via_api! do |commit|
......@@ -62,10 +107,10 @@ module QA
- dotnet restore -p:Configuration=Release
- dotnet build -c Release
- dotnet pack -c Release -p:PackageID=#{package.name}
- dotnet nuget add source "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
- dotnet nuget add source "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name gitlab --username #{auth_token_username} --password #{auth_token_password} --store-password-in-clear-text
- dotnet nuget push "bin/Release/*.nupkg" --source gitlab
only:
- "#{project.default_branch}"
rules:
- if: '$CI_COMMIT_BRANCH == "#{project.default_branch}"'
tags:
- "runner-for-#{project.group.name}"
YAML
......@@ -121,7 +166,7 @@ module QA
stage: install
script:
- dotnet nuget locals all --clear
- dotnet nuget add source "$CI_SERVER_URL/api/v4/groups/#{another_project.group.id}/-/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
- dotnet nuget add source "$CI_SERVER_URL/api/v4/groups/#{another_project.group.id}/-/packages/nuget/index.json" --name gitlab --username #{auth_token_username} --password #{auth_token_password} --store-password-in-clear-text
- "dotnet add otherdotnet.csproj package #{package.name} --version 1.0.0"
only:
- "#{another_project.default_branch}"
......@@ -155,10 +200,11 @@ module QA
Page::Project::Packages::Show.perform(&:click_delete)
Page::Project::Packages::Index.perform do |index|
expect(index).to have_content("Package deleted successfully")
expect(index).to have_content('Package deleted successfully')
expect(index).not_to have_package(package.name)
end
end
end
end
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