Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 09:08:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 09:08:07 +0300
commit232655bf32cd474d54de357b65ef43d77271117c (patch)
treed176e36660e41bb2b629237639015d4dde7d4414 /spec/helpers
parentf5ae9d0960aa422a65a2a22e230100257dddb9ed (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/x509_helper_spec.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/helpers/x509_helper_spec.rb b/spec/helpers/x509_helper_spec.rb
new file mode 100644
index 00000000000..dcdf57ce035
--- /dev/null
+++ b/spec/helpers/x509_helper_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe X509Helper do
+ describe '#x509_subject' do
+ let(:search_uppercase) { %w[CN OU O] }
+ let(:search_lowercase) { %w[cn ou o] }
+ let(:certificate_attributes) do
+ {
+ 'CN' => 'CA Issuing',
+ 'OU' => 'Trust Center',
+ 'O' => 'Example'
+ }
+ end
+
+ context 'with uppercase DN' do
+ let(:upper_dn) { 'CN=CA Issuing,OU=Trust Center,O=Example,L=World,C=Galaxy' }
+
+ it 'returns the attributes on any case search' do
+ expect(x509_subject(upper_dn, search_lowercase)).to eq(certificate_attributes)
+ expect(x509_subject(upper_dn, search_uppercase)).to eq(certificate_attributes)
+ end
+ end
+
+ context 'with lowercase DN' do
+ let(:lower_dn) { 'cn=CA Issuing,ou=Trust Center,o=Example,l=World,c=Galaxy' }
+
+ it 'returns the attributes on any case search' do
+ expect(x509_subject(lower_dn, search_lowercase)).to eq(certificate_attributes)
+ expect(x509_subject(lower_dn, search_uppercase)).to eq(certificate_attributes)
+ end
+ end
+
+ context 'with comma within DN' do
+ let(:comma_dn) { 'cn=CA\, Issuing,ou=Trust Center,o=Example,l=World,c=Galaxy' }
+ let(:certificate_attributes) do
+ {
+ 'CN' => 'CA, Issuing',
+ 'OU' => 'Trust Center',
+ 'O' => 'Example'
+ }
+ end
+
+ it 'returns the attributes on any case search' do
+ expect(x509_subject(comma_dn, search_lowercase)).to eq(certificate_attributes)
+ expect(x509_subject(comma_dn, search_uppercase)).to eq(certificate_attributes)
+ end
+ end
+
+ context 'with mal formed DN' do
+ let(:bad_dn) { 'cn=CA, Issuing,ou=Trust Center,o=Example,l=World,c=Galaxy' }
+
+ it 'returns nil on any case search' do
+ expect(x509_subject(bad_dn, search_lowercase)).to eq({})
+ expect(x509_subject(bad_dn, search_uppercase)).to eq({})
+ end
+ end
+ end
+end