grid-proxy 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,194 @@
1
+ require 'spec_helper'
2
+
3
+ describe GP::Proxy do
4
+ include CrtHelpers
5
+
6
+ subject { GP::Proxy.new proxy_payload }
7
+
8
+ let(:simple_ca) { load_cert 'simple_ca.crt' }
9
+ let(:simple_ca_crl) { load_cert 'simple_ca.crl' }
10
+
11
+
12
+ it 'loads proxy' do
13
+ expect(subject.proxycert).to be_an_instance_of OpenSSL::X509::Certificate
14
+ end
15
+
16
+ it 'loads user cert' do
17
+ expect(subject.usercert).to be_an_instance_of OpenSSL::X509::Certificate
18
+ end
19
+
20
+ describe '#verify!' do
21
+ context 'when time is ok' do
22
+ before do
23
+ Time.stub(:now).and_return(Time.new(2013, 12, 4, 12, 0, 0, "+01:00"))
24
+ end
25
+
26
+ context 'and user cert is signed by ca' do
27
+ it 'does not throw any exception - proxy is verify' do
28
+ subject.verify! simple_ca
29
+ end
30
+ end
31
+
32
+ context 'and user cert is not signed by ca' do
33
+ let(:polish_grid_ca) { load_cert('other_ca.crt') }
34
+
35
+ it 'throws usercert not signed with trusted certificate' do
36
+ expect_validation_error('Usercert not signed with trusted certificate', polish_grid_ca)
37
+ end
38
+ end
39
+
40
+ context 'and proxy is signed by other user cert' do
41
+ subject { GP::Proxy.new(load_cert 'proxy_and_differnt_user_cert') }
42
+
43
+ it 'throws proxy not signed with user certificate' do
44
+ expect_validation_error('Proxy not signed with user certificate', simple_ca)
45
+ end
46
+ end
47
+
48
+ context 'and proxy subject does not begin with the issuer' do
49
+ subject { GP::Proxy.new load_cert('wrong_subject') }
50
+
51
+ it 'throws proxy subject must begin with the issuer' do
52
+ expect_validation_error('Proxy subject must begin with the issuer', simple_ca)
53
+ end
54
+ end
55
+
56
+ context 'and proxy is not actual proxy ("/CN=" not in subject difference")' do
57
+ subject { GP::Proxy.new load_cert('no_proxy') }
58
+ it "throws couldn't find '/CN=' in DN, not a proxy" do
59
+ expect_validation_error("Couldn't find '/CN=' in DN, not a proxy", simple_ca)
60
+ end
61
+ end
62
+
63
+ context 'and proxy is signed by other user cert' do
64
+ subject { GP::Proxy.new load_cert('wrong_issuer') }
65
+
66
+ it 'throws proxy and user cert mismatch' do
67
+ expect_validation_error('Proxy and user cert mismatch', simple_ca)
68
+ end
69
+ end
70
+ end
71
+
72
+ context 'when it is to early' do
73
+ before do
74
+ Time.stub(:now).and_return(Time.new(2013, 12, 3, 12, 0, 0, "+01:00"))
75
+ end
76
+
77
+ it 'throws proxy is not valid yet' do
78
+ expect_validation_error('Proxy is not valid yet', simple_ca)
79
+ end
80
+ end
81
+
82
+ context 'when it is to late' do
83
+ before do
84
+ Time.stub(:now).and_return(Time.new(2013, 12, 5, 12, 0, 0, "+01:00"))
85
+ end
86
+
87
+ it 'throws proxy expired' do
88
+ expect_validation_error('Proxy expired', simple_ca)
89
+ end
90
+ end
91
+
92
+ context 'with invalid proxy key' do
93
+ before do
94
+ Time.stub(:now).and_return(Time.new(2013, 12, 4, 12, 0, 0, "+01:00"))
95
+ end
96
+
97
+ context 'when private key does not exist' do
98
+ subject { GP::Proxy.new(load_cert('without_private_key')) }
99
+
100
+ it 'throws missing proxy private key' do
101
+ expect_validation_error('Private proxy key missing', simple_ca)
102
+ end
103
+ end
104
+
105
+ context 'when cert and private key does not match' do
106
+ subject { GP::Proxy.new(load_cert('cert_and_key_mismatch')) }
107
+ it 'throws private key and cert mismatch' do
108
+ expect_validation_error('Private proxy key and cert mismatch', simple_ca)
109
+ end
110
+ end
111
+ end
112
+
113
+ context 'check for revokation of cert' do
114
+ before do
115
+ Time.stub(:now).and_return(Time.new(2014, 4, 14, 20, 0, 0, "+01:00"))
116
+ end
117
+
118
+ context 'usercert was revoked' do
119
+ subject { GP::Proxy.new load_cert('proxy_revoked.pem') }
120
+
121
+ it 'throws proper exception' do
122
+ expect_validation_error("User cert was revoked", simple_ca, simple_ca_crl)
123
+ end
124
+ end
125
+
126
+ context 'usercert was not revoked' do
127
+ subject { GP::Proxy.new load_cert('proxy_notrevoked.pem') }
128
+
129
+ it 'does not throw exception' do
130
+ subject.verify! simple_ca, simple_ca_crl
131
+ end
132
+ end
133
+ end
134
+
135
+ context 'when user cert is outdated' do
136
+ subject { GP::Proxy.new load_cert('proxy_signed_by_outdated_cert.pem') }
137
+ before do
138
+ Time.stub(:now).and_return(Time.new(2015, 9, 1, 20, 0, 0, "+01:00"))
139
+ end
140
+
141
+ it 'throws exception' do
142
+ expect_validation_error('Proxy signed by outdated certificate',
143
+ simple_ca)
144
+ end
145
+ end
146
+ end
147
+
148
+ describe '#valid?' do
149
+ context 'when proxy is valid' do
150
+ before do
151
+ Time.stub(:now).and_return(Time.new(2013, 12, 4, 12, 0, 0, "+01:00"))
152
+ end
153
+
154
+ it 'returns true' do
155
+ expect(subject.valid? simple_ca).to eq true
156
+ end
157
+ end
158
+
159
+ context 'when proxy is not valid' do
160
+ it 'returns false' do
161
+ expect(subject.valid? simple_ca).to eq false
162
+ end
163
+ end
164
+ end
165
+
166
+ describe '#username' do
167
+ it 'returns username from proxy subject' do
168
+ expect(subject.username).to eq 'plgkasztelnik'
169
+ end
170
+ end
171
+
172
+ describe '#proxy_payload' do
173
+ it 'returns proxy payload' do
174
+ expect(subject.proxy_payload).to eq proxy_payload
175
+ end
176
+ end
177
+
178
+ describe '#revoked?' do
179
+
180
+ context 'when proxy is not revoked' do
181
+ subject { GP::Proxy.new(load_cert('proxy_notrevoked.pem')) }
182
+ it 'returns false' do
183
+ expect(subject.revoked? simple_ca_crl).to be_false
184
+ end
185
+ end
186
+
187
+ context 'when proxy is revoked' do
188
+ subject { GP::Proxy.new(load_cert('proxy_revoked.pem')) }
189
+ it 'returns true' do
190
+ expect(subject.revoked? simple_ca_crl).to be_true
191
+ end
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,17 @@
1
+ require 'grid-proxy'
2
+
3
+ Dir["#{File.dirname(__FILE__)}/support/*.rb"].each do |file|
4
+ require file
5
+ end
6
+
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
@@ -0,0 +1,15 @@
1
+ module CrtHelpers
2
+ def proxy_payload
3
+ @proxy_payload ||= load_cert('valid_proxy')
4
+ end
5
+
6
+ def load_cert(cert_name)
7
+ File.read File.join(File.dirname(__FILE__), '..', 'certs', cert_name)
8
+ end
9
+
10
+ def expect_validation_error(error_msg, ca, crl = nil)
11
+ expect {
12
+ subject.verify! ca, crl
13
+ }.to raise_error(GP::ProxyValidationError, error_msg)
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grid-proxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marek Kasztelnik
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Grid proxy utils
42
+ email:
43
+ - mkasztelnik@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - Gemfile
51
+ - Guardfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - grid-proxy.gemspec
56
+ - lib/grid-proxy.rb
57
+ - lib/grid-proxy/exceptions.rb
58
+ - lib/grid-proxy/proxy.rb
59
+ - lib/grid-proxy/version.rb
60
+ - spec/certs/cert_and_key_mismatch
61
+ - spec/certs/invalid_proxy
62
+ - spec/certs/no_proxy
63
+ - spec/certs/other_ca.crt
64
+ - spec/certs/proxy_and_differnt_user_cert
65
+ - spec/certs/proxy_notrevoked.pem
66
+ - spec/certs/proxy_revoked.pem
67
+ - spec/certs/proxy_signed_by_outdated_cert.pem
68
+ - spec/certs/simple_ca.crl
69
+ - spec/certs/simple_ca.crt
70
+ - spec/certs/valid_proxy
71
+ - spec/certs/without_private_key
72
+ - spec/certs/wrong_issuer
73
+ - spec/certs/wrong_subject
74
+ - spec/grid-proxy/proxy_spec.rb
75
+ - spec/spec_helper.rb
76
+ - spec/support/crt_helpers.rb
77
+ homepage: https://github.com/dice-cyfronet/grid-proxy
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.5.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Grid proxy utils
101
+ test_files:
102
+ - spec/certs/cert_and_key_mismatch
103
+ - spec/certs/invalid_proxy
104
+ - spec/certs/no_proxy
105
+ - spec/certs/other_ca.crt
106
+ - spec/certs/proxy_and_differnt_user_cert
107
+ - spec/certs/proxy_notrevoked.pem
108
+ - spec/certs/proxy_revoked.pem
109
+ - spec/certs/proxy_signed_by_outdated_cert.pem
110
+ - spec/certs/simple_ca.crl
111
+ - spec/certs/simple_ca.crt
112
+ - spec/certs/valid_proxy
113
+ - spec/certs/without_private_key
114
+ - spec/certs/wrong_issuer
115
+ - spec/certs/wrong_subject
116
+ - spec/grid-proxy/proxy_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/support/crt_helpers.rb