diff options
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/auth_spec.rb | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/email/hook/smime_signature_interceptor_spec.rb | 17 | ||||
-rw-r--r-- | spec/lib/gitlab/tab_width_spec.rb | 31 |
3 files changed, 62 insertions, 4 deletions
diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb index 1f943bebbec..ed763f63756 100644 --- a/spec/lib/gitlab/auth_spec.rb +++ b/spec/lib/gitlab/auth_spec.rb @@ -460,6 +460,20 @@ describe Gitlab::Auth, :use_clean_rails_memory_store_caching do end end + context 'when the deploy token is of group type' do + let(:project_with_group) { create(:project, group: create(:group)) } + let(:deploy_token) { create(:deploy_token, :group, read_repository: true, groups: [project_with_group.group]) } + let(:login) { deploy_token.username } + + subject { gl_auth.find_for_git_client(login, deploy_token.token, project: project_with_group, ip: 'ip') } + + it 'succeeds when login and a group deploy token are valid' do + auth_success = Gitlab::Auth::Result.new(deploy_token, project_with_group, :deploy_token, [:download_code, :read_container_image]) + + expect(subject).to eq(auth_success) + end + end + context 'when the deploy token has read_registry as a scope' do let(:deploy_token) { create(:deploy_token, read_repository: false, projects: [project]) } let(:login) { deploy_token.username } @@ -469,10 +483,10 @@ describe Gitlab::Auth, :use_clean_rails_memory_store_caching do stub_container_registry_config(enabled: true) end - it 'succeeds when login and token are valid' do + it 'succeeds when login and a project token are valid' do auth_success = Gitlab::Auth::Result.new(deploy_token, project, :deploy_token, [:read_container_image]) - expect(gl_auth.find_for_git_client(login, deploy_token.token, project: nil, ip: 'ip')) + expect(gl_auth.find_for_git_client(login, deploy_token.token, project: project, ip: 'ip')) .to eq(auth_success) end diff --git a/spec/lib/gitlab/email/hook/smime_signature_interceptor_spec.rb b/spec/lib/gitlab/email/hook/smime_signature_interceptor_spec.rb index a65214fab61..36954252b6b 100644 --- a/spec/lib/gitlab/email/hook/smime_signature_interceptor_spec.rb +++ b/spec/lib/gitlab/email/hook/smime_signature_interceptor_spec.rb @@ -20,8 +20,14 @@ describe Gitlab::Email::Hook::SmimeSignatureInterceptor do Gitlab::Email::Smime::Certificate.new(@cert[:key], @cert[:cert]) end + let(:mail_body) { "signed hello with Unicode €áø and\r\n newlines\r\n" } + let(:mail) do - ActionMailer::Base.mail(to: 'test@example.com', from: 'info@example.com', body: 'signed hello') + ActionMailer::Base.mail(to: 'test@example.com', + from: 'info@example.com', + content_transfer_encoding: 'quoted-printable', + content_type: 'text/plain; charset=UTF-8', + body: mail_body) end before do @@ -46,9 +52,16 @@ describe Gitlab::Email::Hook::SmimeSignatureInterceptor do ca_cert: root_certificate.cert, signed_data: mail.encoded) + # re-verify signature from a new Mail object content + # See https://gitlab.com/gitlab-org/gitlab/issues/197386 + Gitlab::Email::Smime::Signer.verify_signature( + cert: certificate.cert, + ca_cert: root_certificate.cert, + signed_data: Mail.new(mail).encoded) + # envelope in a Mail object and obtain the body decoded_mail = Mail.new(p7enc.data) - expect(decoded_mail.body.encoded).to eq('signed hello') + expect(decoded_mail.body.decoded.dup.force_encoding(decoded_mail.charset)).to eq(mail_body) end end diff --git a/spec/lib/gitlab/tab_width_spec.rb b/spec/lib/gitlab/tab_width_spec.rb new file mode 100644 index 00000000000..3b5014d27e4 --- /dev/null +++ b/spec/lib/gitlab/tab_width_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +describe Gitlab::TabWidth, lib: true do + describe '.css_class_for_user' do + it 'returns default CSS class when user is nil' do + css_class = described_class.css_class_for_user(nil) + + expect(css_class).to eq('tab-width-8') + end + + it "returns CSS class for user's tab width", :aggregate_failures do + [1, 6, 12].each do |i| + user = double('user', tab_width: i) + css_class = described_class.css_class_for_user(user) + + expect(css_class).to eq("tab-width-#{i}") + end + end + + it 'raises if tab width is out of valid range', :aggregate_failures do + [0, 13, 'foo', nil].each do |i| + expect do + user = double('user', tab_width: i) + described_class.css_class_for_user(user) + end.to raise_error(ArgumentError) + end + end + end +end |