diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-31 15:11:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-31 15:11:01 +0300 |
commit | f52f8542b47c9e00ddf420abaf2263de168988f9 (patch) | |
tree | 568225882da5cc4deb746d2d4fc362c6076fb708 /spec/support/helpers/packages_manager_api_spec_helpers.rb | |
parent | 6a5ef9b75d38f39cd2a6a2392fadfbd3b966b884 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/helpers/packages_manager_api_spec_helpers.rb')
-rw-r--r-- | spec/support/helpers/packages_manager_api_spec_helpers.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/support/helpers/packages_manager_api_spec_helpers.rb b/spec/support/helpers/packages_manager_api_spec_helpers.rb new file mode 100644 index 00000000000..1c9fce183e9 --- /dev/null +++ b/spec/support/helpers/packages_manager_api_spec_helpers.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module PackagesManagerApiSpecHelpers + def build_jwt(personal_access_token, secret: jwt_secret, user_id: nil) + JSONWebToken::HMACToken.new(secret).tap do |jwt| + jwt['access_token'] = personal_access_token.token + jwt['user_id'] = user_id || personal_access_token.user_id + end + end + + def build_jwt_from_job(job, secret: jwt_secret) + JSONWebToken::HMACToken.new(secret).tap do |jwt| + jwt['access_token'] = job.token + jwt['user_id'] = job.user.id + end + end + + def build_jwt_from_deploy_token(deploy_token, secret: jwt_secret) + JSONWebToken::HMACToken.new(secret).tap do |jwt| + jwt['access_token'] = deploy_token.token + jwt['user_id'] = deploy_token.username + end + end + + def temp_file(package_tmp) + upload_path = ::Packages::PackageFileUploader.workhorse_local_upload_path + file_path = "#{upload_path}/#{package_tmp}" + + FileUtils.mkdir_p(upload_path) + File.write(file_path, 'test') + + UploadedFile.new(file_path, filename: File.basename(file_path)) + end +end |