summaryrefslogtreecommitdiff
path: root/spec/support/helpers/dependency_proxy_helpers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers/dependency_proxy_helpers.rb')
-rw-r--r--spec/support/helpers/dependency_proxy_helpers.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/spec/support/helpers/dependency_proxy_helpers.rb b/spec/support/helpers/dependency_proxy_helpers.rb
index 545b9d1f4d0..ebb849628bf 100644
--- a/spec/support/helpers/dependency_proxy_helpers.rb
+++ b/spec/support/helpers/dependency_proxy_helpers.rb
@@ -11,11 +11,18 @@ module DependencyProxyHelpers
.to_return(status: status, body: body || auth_body)
end
- def stub_manifest_download(image, tag, status = 200, body = nil)
+ def stub_manifest_download(image, tag, status: 200, body: nil, headers: {})
manifest_url = registry.manifest_url(image, tag)
stub_full_request(manifest_url)
- .to_return(status: status, body: body || manifest)
+ .to_return(status: status, body: body || manifest, headers: headers)
+ end
+
+ def stub_manifest_head(image, tag, status: 200, body: nil, digest: '123456')
+ manifest_url = registry.manifest_url(image, tag)
+
+ stub_full_request(manifest_url, method: :head)
+ .to_return(status: status, body: body, headers: { 'docker-content-digest' => digest } )
end
def stub_blob_download(image, blob_sha, status = 200, body = '123456')
@@ -25,6 +32,13 @@ module DependencyProxyHelpers
.to_return(status: status, body: body)
end
+ def build_jwt(user = nil, expire_time: nil)
+ JSONWebToken::HMACToken.new(::Auth::DependencyProxyAuthenticationService.secret).tap do |jwt|
+ jwt['user_id'] = user.id if user
+ jwt.expire_time = expire_time || jwt.issued_at + 1.minute
+ end
+ end
+
private
def registry