rkerberos 0.2.2 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGES.md +22 -0
- data/EXAMPLES.md +1015 -0
- data/MANIFEST.md +17 -12
- data/README.md +5 -5
- data/ext/rkerberos/ccache.c +105 -26
- data/ext/rkerberos/config.c +59 -10
- data/ext/rkerberos/context.c +76 -7
- data/ext/rkerberos/extconf.rb +16 -3
- data/ext/rkerberos/kadm5.c +301 -96
- data/ext/rkerberos/keytab.c +222 -66
- data/ext/rkerberos/keytab_entry.c +2 -1
- data/ext/rkerberos/policy.c +25 -23
- data/ext/rkerberos/principal.c +136 -10
- data/ext/rkerberos/rkerberos.c +244 -34
- data/ext/rkerberos/rkerberos.h +8 -0
- data/rkerberos.gemspec +10 -7
- data/spec/config_spec.rb +58 -3
- data/spec/context_spec.rb +57 -7
- data/spec/credentials_cache_spec.rb +106 -39
- data/spec/kadm5_spec.rb +292 -17
- data/spec/krb5_keytab_spec.rb +229 -24
- data/spec/krb5_spec.rb +142 -29
- data/spec/policy_spec.rb +12 -7
- data/spec/principal_spec.rb +102 -4
- data/spec/spec_helper.rb +34 -0
- metadata +10 -8
data/spec/config_spec.rb
CHANGED
|
@@ -1,19 +1,54 @@
|
|
|
1
1
|
# spec/config_spec.rb
|
|
2
2
|
# RSpec tests for Kerberos::Kadm5::Config
|
|
3
3
|
|
|
4
|
-
require '
|
|
4
|
+
require 'spec_helper'
|
|
5
5
|
|
|
6
|
-
RSpec.describe Kerberos::Kadm5::Config do
|
|
7
|
-
subject(:
|
|
6
|
+
RSpec.describe 'Kerberos::Kadm5::Config', :kadm5 do
|
|
7
|
+
subject(:klass){ Kerberos::Kadm5::Config }
|
|
8
|
+
let(:config) { klass.new }
|
|
8
9
|
|
|
9
10
|
it 'is frozen' do
|
|
10
11
|
expect(config).to be_frozen
|
|
11
12
|
end
|
|
12
13
|
|
|
14
|
+
describe 'constructor' do
|
|
15
|
+
it 'can be called with no arguments' do
|
|
16
|
+
expect { klass.new }.not_to raise_error
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'accepts a context option' do
|
|
20
|
+
ctx = Kerberos::Krb5::Context.new
|
|
21
|
+
expect { klass.new(context: ctx) }.not_to raise_error
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'returns same realm with or without context' do
|
|
25
|
+
ctx = Kerberos::Krb5::Context.new
|
|
26
|
+
c1 = klass.new
|
|
27
|
+
c2 = klass.new(context: ctx)
|
|
28
|
+
expect(c2.realm).to eq(c1.realm)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'raises TypeError for non-Context context argument' do
|
|
32
|
+
expect { klass.new(context: "bad") }.to raise_error(TypeError)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'raises error for a closed context' do
|
|
36
|
+
ctx = Kerberos::Krb5::Context.new
|
|
37
|
+
ctx.close
|
|
38
|
+
expect { klass.new(context: ctx) }.to raise_error(Kerberos::Krb5::Exception)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'rejects positional option hashes and unknown keywords' do
|
|
42
|
+
expect { klass.new({context: nil}) }.to raise_error(ArgumentError)
|
|
43
|
+
expect { klass.new(unknown: true) }.to raise_error(ArgumentError, /unknown keyword/)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
13
47
|
describe 'realm' do
|
|
14
48
|
it 'responds to realm' do
|
|
15
49
|
expect(config).to respond_to(:realm)
|
|
16
50
|
end
|
|
51
|
+
|
|
17
52
|
it 'returns a String' do
|
|
18
53
|
expect(config.realm).to be_a(String)
|
|
19
54
|
end
|
|
@@ -23,6 +58,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
23
58
|
it 'responds to kadmind_port' do
|
|
24
59
|
expect(config).to respond_to(:kadmind_port)
|
|
25
60
|
end
|
|
61
|
+
|
|
26
62
|
it 'returns an Integer' do
|
|
27
63
|
expect(config.kadmind_port).to be_a(Integer)
|
|
28
64
|
end
|
|
@@ -32,6 +68,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
32
68
|
it 'responds to kpasswd_port' do
|
|
33
69
|
expect(config).to respond_to(:kpasswd_port)
|
|
34
70
|
end
|
|
71
|
+
|
|
35
72
|
it 'returns an Integer' do
|
|
36
73
|
expect(config.kpasswd_port).to be_a(Integer)
|
|
37
74
|
end
|
|
@@ -41,6 +78,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
41
78
|
it 'responds to admin_server' do
|
|
42
79
|
expect(config).to respond_to(:admin_server)
|
|
43
80
|
end
|
|
81
|
+
|
|
44
82
|
it 'returns a String' do
|
|
45
83
|
expect(config.admin_server).to be_a(String)
|
|
46
84
|
end
|
|
@@ -50,6 +88,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
50
88
|
it 'responds to acl_file' do
|
|
51
89
|
expect(config).to respond_to(:acl_file)
|
|
52
90
|
end
|
|
91
|
+
|
|
53
92
|
it 'returns a String' do
|
|
54
93
|
expect(config.acl_file).to be_a(String)
|
|
55
94
|
end
|
|
@@ -59,6 +98,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
59
98
|
it 'responds to dict_file' do
|
|
60
99
|
expect(config).to respond_to(:dict_file)
|
|
61
100
|
end
|
|
101
|
+
|
|
62
102
|
it 'returns a String or nil' do
|
|
63
103
|
expect([String, NilClass]).to include(config.dict_file.class)
|
|
64
104
|
end
|
|
@@ -68,6 +108,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
68
108
|
it 'responds to stash_file' do
|
|
69
109
|
expect(config).to respond_to(:stash_file)
|
|
70
110
|
end
|
|
111
|
+
|
|
71
112
|
it 'returns a String or nil' do
|
|
72
113
|
expect([String, NilClass]).to include(config.stash_file.class)
|
|
73
114
|
end
|
|
@@ -77,6 +118,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
77
118
|
it 'responds to mkey_name' do
|
|
78
119
|
expect(config).to respond_to(:mkey_name)
|
|
79
120
|
end
|
|
121
|
+
|
|
80
122
|
it 'returns a String or nil' do
|
|
81
123
|
expect([String, NilClass]).to include(config.mkey_name.class)
|
|
82
124
|
end
|
|
@@ -86,6 +128,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
86
128
|
it 'responds to mkey_from_kbd' do
|
|
87
129
|
expect(config).to respond_to(:mkey_from_kbd)
|
|
88
130
|
end
|
|
131
|
+
|
|
89
132
|
it 'returns an Integer or nil' do
|
|
90
133
|
expect([Integer, NilClass]).to include(config.mkey_from_kbd.class)
|
|
91
134
|
end
|
|
@@ -95,6 +138,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
95
138
|
it 'responds to enctype' do
|
|
96
139
|
expect(config).to respond_to(:enctype)
|
|
97
140
|
end
|
|
141
|
+
|
|
98
142
|
it 'returns an Integer' do
|
|
99
143
|
expect(config.enctype).to be_a(Integer)
|
|
100
144
|
end
|
|
@@ -104,6 +148,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
104
148
|
it 'responds to max_life' do
|
|
105
149
|
expect(config).to respond_to(:max_life)
|
|
106
150
|
end
|
|
151
|
+
|
|
107
152
|
it 'returns an Integer' do
|
|
108
153
|
expect(config.max_life).to be_a(Integer)
|
|
109
154
|
end
|
|
@@ -113,6 +158,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
113
158
|
it 'responds to max_rlife' do
|
|
114
159
|
expect(config).to respond_to(:max_rlife)
|
|
115
160
|
end
|
|
161
|
+
|
|
116
162
|
it 'returns an Integer' do
|
|
117
163
|
expect(config.max_rlife).to be_a(Integer)
|
|
118
164
|
end
|
|
@@ -122,6 +168,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
122
168
|
it 'responds to expiration' do
|
|
123
169
|
expect(config).to respond_to(:expiration)
|
|
124
170
|
end
|
|
171
|
+
|
|
125
172
|
it 'returns a Time or nil' do
|
|
126
173
|
expect([Time, NilClass]).to include(config.expiration.class)
|
|
127
174
|
end
|
|
@@ -131,6 +178,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
131
178
|
it 'responds to kvno' do
|
|
132
179
|
expect(config).to respond_to(:kvno)
|
|
133
180
|
end
|
|
181
|
+
|
|
134
182
|
it 'returns an Integer or nil' do
|
|
135
183
|
expect([Integer, NilClass]).to include(config.kvno.class)
|
|
136
184
|
end
|
|
@@ -140,6 +188,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
140
188
|
it 'responds to iprop_enabled' do
|
|
141
189
|
expect(config).to respond_to(:iprop_enabled)
|
|
142
190
|
end
|
|
191
|
+
|
|
143
192
|
it 'returns a boolean' do
|
|
144
193
|
expect(!!config.iprop_enabled == config.iprop_enabled).to be true
|
|
145
194
|
end
|
|
@@ -149,6 +198,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
149
198
|
it 'responds to iprop_logfile' do
|
|
150
199
|
expect(config).to respond_to(:iprop_logfile)
|
|
151
200
|
end
|
|
201
|
+
|
|
152
202
|
it 'returns a String' do
|
|
153
203
|
expect(config.iprop_logfile).to be_a(String)
|
|
154
204
|
end
|
|
@@ -158,6 +208,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
158
208
|
it 'responds to iprop_poll_time' do
|
|
159
209
|
expect(config).to respond_to(:iprop_poll_time)
|
|
160
210
|
end
|
|
211
|
+
|
|
161
212
|
it 'returns an Integer' do
|
|
162
213
|
expect(config.iprop_poll_time).to be_a(Integer)
|
|
163
214
|
end
|
|
@@ -167,6 +218,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
167
218
|
it 'responds to iprop_port' do
|
|
168
219
|
expect(config).to respond_to(:iprop_port)
|
|
169
220
|
end
|
|
221
|
+
|
|
170
222
|
it 'returns an Integer or nil' do
|
|
171
223
|
expect([Integer, NilClass]).to include(config.iprop_port.class)
|
|
172
224
|
end
|
|
@@ -176,6 +228,7 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
176
228
|
it 'responds to num_keysalts' do
|
|
177
229
|
expect(config).to respond_to(:num_keysalts)
|
|
178
230
|
end
|
|
231
|
+
|
|
179
232
|
it 'returns an Integer' do
|
|
180
233
|
expect(config.num_keysalts).to be_a(Integer)
|
|
181
234
|
end
|
|
@@ -185,9 +238,11 @@ RSpec.describe Kerberos::Kadm5::Config do
|
|
|
185
238
|
it 'responds to keysalts' do
|
|
186
239
|
expect(config).to respond_to(:keysalts)
|
|
187
240
|
end
|
|
241
|
+
|
|
188
242
|
it 'returns an Array' do
|
|
189
243
|
expect(config.keysalts).to be_a(Array)
|
|
190
244
|
end
|
|
245
|
+
|
|
191
246
|
it 'contains KeySalt objects if not empty' do
|
|
192
247
|
unless config.keysalts.empty?
|
|
193
248
|
expect(config.keysalts.first).to be_a(Kerberos::Kadm5::KeySalt)
|
data/spec/context_spec.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# spec/context_spec.rb
|
|
2
2
|
# RSpec tests for Kerberos::Krb5::Context
|
|
3
3
|
|
|
4
|
-
require '
|
|
4
|
+
require 'spec_helper'
|
|
5
5
|
|
|
6
6
|
RSpec.describe Kerberos::Krb5::Context do
|
|
7
7
|
subject(:context) { described_class.new }
|
|
@@ -19,17 +19,18 @@ RSpec.describe Kerberos::Krb5::Context do
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
describe 'constructor options' do
|
|
22
|
+
let(:profile_path){ RSpec.configuration.krb5_conf }
|
|
23
|
+
|
|
22
24
|
it 'accepts secure: true to use a secure context' do
|
|
23
25
|
expect { described_class.new(secure: true) }.not_to raise_error
|
|
24
26
|
end
|
|
25
27
|
|
|
26
|
-
it 'accepts a profile path via :profile' do
|
|
27
|
-
profile_path = ENV['KRB5_CONFIG'] || '/etc/krb5.conf'
|
|
28
|
+
it 'accepts a profile path via :profile', :unix do
|
|
28
29
|
expect(File).to exist(profile_path)
|
|
29
30
|
expect { described_class.new(profile: profile_path) }.not_to raise_error
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
it 'validates profile argument type' do
|
|
33
|
+
it 'validates profile argument type', :unix do
|
|
33
34
|
expect { described_class.new(profile: 123) }.to raise_error(TypeError)
|
|
34
35
|
end
|
|
35
36
|
|
|
@@ -43,15 +44,64 @@ RSpec.describe Kerberos::Krb5::Context do
|
|
|
43
44
|
end
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
it 'accepts secure: true together with profile' do
|
|
47
|
-
profile_path = ENV['KRB5_CONFIG'] || '/etc/krb5.conf'
|
|
47
|
+
it 'accepts secure: true together with profile', :unix do
|
|
48
48
|
expect(File).to exist(profile_path)
|
|
49
|
-
|
|
50
49
|
ctx = nil
|
|
51
50
|
expect { ctx = described_class.new(secure: true, profile: profile_path) }.not_to raise_error
|
|
52
51
|
expect(ctx).to be_a(described_class)
|
|
53
52
|
expect { ctx.close }.not_to raise_error
|
|
54
53
|
end
|
|
54
|
+
|
|
55
|
+
it 'rejects positional option hashes and unknown keywords' do
|
|
56
|
+
expect { described_class.new({secure: true}) }.to raise_error(ArgumentError)
|
|
57
|
+
expect { described_class.new(unknown: true) }.to raise_error(ArgumentError, /unknown keyword/)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe '#default_realm' do
|
|
62
|
+
it 'responds to default_realm' do
|
|
63
|
+
expect(context).to respond_to(:default_realm)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'returns a string' do
|
|
67
|
+
expect(context.default_realm).to be_a(String)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'returns a non-empty realm' do
|
|
71
|
+
expect(context.default_realm.size).to be > 0
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'raises when context is closed' do
|
|
75
|
+
context.close
|
|
76
|
+
expect { context.default_realm }.to raise_error(Kerberos::Krb5::Exception)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe '#default_realm=' do
|
|
81
|
+
it 'responds to default_realm=' do
|
|
82
|
+
expect(context).to respond_to(:default_realm=)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'can set and read back a custom realm' do
|
|
86
|
+
context.default_realm = 'TEST.REALM'
|
|
87
|
+
expect(context.default_realm).to eq('TEST.REALM')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'accepts nil to reset to the default' do
|
|
91
|
+
original = context.default_realm
|
|
92
|
+
context.default_realm = 'TEMP.REALM'
|
|
93
|
+
context.default_realm = nil
|
|
94
|
+
expect(context.default_realm).to eq(original)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'raises TypeError for non-string argument' do
|
|
98
|
+
expect { context.default_realm = 123 }.to raise_error(TypeError)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'raises when context is closed' do
|
|
102
|
+
context.close
|
|
103
|
+
expect { context.default_realm = 'X' }.to raise_error(Kerberos::Krb5::Exception)
|
|
104
|
+
end
|
|
55
105
|
end
|
|
56
106
|
|
|
57
107
|
after(:each) do
|
|
@@ -1,71 +1,109 @@
|
|
|
1
1
|
# spec/credentials_cache_spec.rb
|
|
2
2
|
# RSpec tests for Kerberos::Krb5::CredentialsCache
|
|
3
3
|
|
|
4
|
-
require '
|
|
5
|
-
require 'etc'
|
|
4
|
+
require 'spec_helper'
|
|
6
5
|
require 'open3'
|
|
7
|
-
require 'tmpdir'
|
|
8
6
|
|
|
9
7
|
RSpec.describe Kerberos::Krb5::CredentialsCache do
|
|
10
|
-
let(:login) do
|
|
11
|
-
Etc.getlogin || ENV['USER'] || (Etc.getpwuid(Process.uid).name rescue nil)
|
|
12
|
-
end
|
|
13
8
|
let(:realm) { Kerberos::Krb5.new.default_realm }
|
|
14
|
-
let(:princ) {
|
|
15
|
-
let(:cfile) {
|
|
9
|
+
let(:princ) { RSpec.configuration.login + '@' + realm }
|
|
10
|
+
let(:cfile) { RSpec.configuration.krb5_cc_name }
|
|
16
11
|
let(:ccache) { described_class.new }
|
|
17
12
|
|
|
18
13
|
def cache_found?
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
if File::ALT_SEPARATOR
|
|
15
|
+
File.exist?(cfile)
|
|
16
|
+
else
|
|
17
|
+
found = true
|
|
18
|
+
Open3.popen3('klist') { |_, _, stderr| found = false unless stderr.gets.nil? }
|
|
19
|
+
found
|
|
20
|
+
end
|
|
22
21
|
end
|
|
23
22
|
|
|
24
23
|
after(:each) do
|
|
25
|
-
Open3.popen3('kdestroy') { sleep 0.1 }
|
|
24
|
+
Open3.popen3('kdestroy -q') { sleep 0.1 } if cache_found?
|
|
26
25
|
end
|
|
27
26
|
|
|
28
27
|
describe 'constructor' do
|
|
29
28
|
it 'can be called with no arguments' do
|
|
30
29
|
expect { described_class.new }.not_to raise_error
|
|
31
30
|
end
|
|
31
|
+
|
|
32
32
|
it 'does not create a cache with no arguments' do
|
|
33
33
|
described_class.new
|
|
34
34
|
expect(File.exist?(cfile)).to be false
|
|
35
35
|
expect(cache_found?).to be false
|
|
36
36
|
end
|
|
37
|
+
|
|
37
38
|
it 'creates a cache with a principal' do
|
|
38
|
-
expect { described_class.new(princ) }.not_to raise_error
|
|
39
|
+
expect { described_class.new(principal: princ) }.not_to raise_error
|
|
39
40
|
expect(File.exist?(cfile)).to be true
|
|
40
41
|
expect(cache_found?).to be true
|
|
41
42
|
end
|
|
43
|
+
|
|
42
44
|
it 'accepts an explicit cache name' do
|
|
43
|
-
expect { described_class.new(princ, cfile) }.not_to raise_error
|
|
44
|
-
expect { described_class.new(
|
|
45
|
+
expect { described_class.new(principal: princ, cache_name: cfile) }.not_to raise_error
|
|
46
|
+
expect { described_class.new(cache_name: cfile) }.not_to raise_error
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'raises error for non-string principal' do
|
|
50
|
+
expect { described_class.new(principal: true) }.to raise_error(TypeError)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'accepts Principal objects (duck-typed as #principal)' do
|
|
54
|
+
obj = Kerberos::Krb5::Principal.new(name: princ)
|
|
55
|
+
expect { described_class.new(principal: obj) }.not_to raise_error
|
|
56
|
+
expect(described_class.new(principal: obj).primary_principal).to eq(princ)
|
|
45
57
|
end
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
|
|
59
|
+
it 'raises error for positional arguments' do
|
|
60
|
+
expect { described_class.new(princ) }.to raise_error(ArgumentError)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'rejects unknown keywords' do
|
|
64
|
+
expect { described_class.new(unknown: true) }.to raise_error(ArgumentError, /unknown keyword/)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'accepts a context option' do
|
|
68
|
+
ctx = Kerberos::Krb5::Context.new
|
|
69
|
+
expect { described_class.new(principal: princ, context: ctx) }.not_to raise_error
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'uses the context when provided' do
|
|
73
|
+
ctx = Kerberos::Krb5::Context.new
|
|
74
|
+
c = described_class.new(principal: princ, context: ctx)
|
|
75
|
+
expect(c.primary_principal).to eq(princ)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'raises TypeError for non-Context context argument' do
|
|
79
|
+
expect { described_class.new(context: "bad") }.to raise_error(TypeError)
|
|
48
80
|
end
|
|
49
|
-
|
|
50
|
-
|
|
81
|
+
|
|
82
|
+
it 'raises error for a closed context' do
|
|
83
|
+
ctx = Kerberos::Krb5::Context.new
|
|
84
|
+
ctx.close
|
|
85
|
+
expect { described_class.new(context: ctx) }.to raise_error(Kerberos::Krb5::Exception)
|
|
51
86
|
end
|
|
52
87
|
end
|
|
53
88
|
|
|
54
89
|
describe '#close' do
|
|
55
90
|
it 'responds to close' do
|
|
56
|
-
expect(described_class.new(princ)).to respond_to(:close)
|
|
91
|
+
expect(described_class.new(principal: princ)).to respond_to(:close)
|
|
57
92
|
end
|
|
93
|
+
|
|
58
94
|
it 'does not delete credentials cache' do
|
|
59
|
-
c = described_class.new(princ)
|
|
95
|
+
c = described_class.new(principal: princ)
|
|
60
96
|
expect { c.close }.not_to raise_error
|
|
61
97
|
expect(cache_found?).to be true
|
|
62
98
|
end
|
|
99
|
+
|
|
63
100
|
it 'can be called multiple times without error' do
|
|
64
|
-
c = described_class.new(princ)
|
|
101
|
+
c = described_class.new(principal: princ)
|
|
65
102
|
expect { 3.times { c.close } }.not_to raise_error
|
|
66
103
|
end
|
|
104
|
+
|
|
67
105
|
it 'raises error when calling method on closed object' do
|
|
68
|
-
c = described_class.new(princ)
|
|
106
|
+
c = described_class.new(principal: princ)
|
|
69
107
|
c.close
|
|
70
108
|
expect { c.default_name }.to raise_error(Kerberos::Krb5::Exception)
|
|
71
109
|
end
|
|
@@ -73,19 +111,20 @@ RSpec.describe Kerberos::Krb5::CredentialsCache do
|
|
|
73
111
|
|
|
74
112
|
describe '#default_name' do
|
|
75
113
|
it 'responds to default_name' do
|
|
76
|
-
c = described_class.new(princ)
|
|
114
|
+
c = described_class.new(principal: princ)
|
|
77
115
|
expect(c).to respond_to(:default_name)
|
|
78
116
|
expect { c.default_name }.not_to raise_error
|
|
79
117
|
end
|
|
118
|
+
|
|
80
119
|
it 'returns a string' do
|
|
81
|
-
c = described_class.new(princ)
|
|
120
|
+
c = described_class.new(principal: princ)
|
|
82
121
|
expect(c.default_name).to be_a(String)
|
|
83
122
|
end
|
|
84
123
|
end
|
|
85
124
|
|
|
86
125
|
describe '#cache_name and #cache_type' do
|
|
87
126
|
it 'returns the ccache name and type' do
|
|
88
|
-
c = described_class.new(princ)
|
|
127
|
+
c = described_class.new(principal: princ)
|
|
89
128
|
expect(c).to respond_to(:cache_name)
|
|
90
129
|
expect(c).to respond_to(:cache_type)
|
|
91
130
|
|
|
@@ -94,13 +133,13 @@ RSpec.describe Kerberos::Krb5::CredentialsCache do
|
|
|
94
133
|
|
|
95
134
|
# cache_name returns the residual portion of the cache name; default_name
|
|
96
135
|
# may include the type prefix (e.g. "FILE:"). ensure the suffix matches.
|
|
97
|
-
expect(c.cache_name).to eq(c.default_name.split(
|
|
136
|
+
expect(c.cache_name).to eq(c.default_name.split(/\w{2,}:/).last)
|
|
98
137
|
end
|
|
99
138
|
end
|
|
100
139
|
|
|
101
140
|
describe '#principal' do
|
|
102
141
|
it 'is an alias for primary_principal' do
|
|
103
|
-
c = described_class.new(princ)
|
|
142
|
+
c = described_class.new(principal: princ)
|
|
104
143
|
expect(c).to respond_to(:principal)
|
|
105
144
|
expect(c.principal).to eq(c.primary_principal)
|
|
106
145
|
end
|
|
@@ -108,12 +147,13 @@ RSpec.describe Kerberos::Krb5::CredentialsCache do
|
|
|
108
147
|
|
|
109
148
|
describe '#primary_principal' do
|
|
110
149
|
it 'responds to primary_principal' do
|
|
111
|
-
c = described_class.new(princ)
|
|
150
|
+
c = described_class.new(principal: princ)
|
|
112
151
|
expect(c).to respond_to(:primary_principal)
|
|
113
152
|
expect { c.primary_principal }.not_to raise_error
|
|
114
153
|
end
|
|
154
|
+
|
|
115
155
|
it 'returns expected results' do
|
|
116
|
-
c = described_class.new(princ)
|
|
156
|
+
c = described_class.new(principal: princ)
|
|
117
157
|
expect(c.primary_principal).to be_a(String)
|
|
118
158
|
expect(c.primary_principal.size).to be > 0
|
|
119
159
|
expect(c.primary_principal).to include('@')
|
|
@@ -122,37 +162,42 @@ RSpec.describe Kerberos::Krb5::CredentialsCache do
|
|
|
122
162
|
|
|
123
163
|
describe '#destroy' do
|
|
124
164
|
it 'responds to destroy' do
|
|
125
|
-
c = described_class.new(princ)
|
|
165
|
+
c = described_class.new(principal: princ)
|
|
126
166
|
expect(c).to respond_to(:destroy)
|
|
127
167
|
end
|
|
168
|
+
|
|
128
169
|
it 'deletes credentials cache' do
|
|
129
|
-
c = described_class.new(princ)
|
|
170
|
+
c = described_class.new(principal: princ)
|
|
130
171
|
expect { c.destroy }.not_to raise_error
|
|
131
172
|
expect(cache_found?).to be false
|
|
132
173
|
end
|
|
174
|
+
|
|
133
175
|
it 'delete is an alias for destroy' do
|
|
134
|
-
c = described_class.new(princ)
|
|
176
|
+
c = described_class.new(principal: princ)
|
|
135
177
|
expect(c).to respond_to(:delete)
|
|
136
178
|
expect(c.method(:delete)).to eq(c.method(:destroy))
|
|
137
179
|
end
|
|
180
|
+
|
|
138
181
|
it 'returns false if no credentials cache' do
|
|
139
182
|
c = described_class.new
|
|
140
183
|
expect(c.destroy).to be false
|
|
141
184
|
end
|
|
185
|
+
|
|
142
186
|
it 'raises error when calling method on destroyed object' do
|
|
143
|
-
c = described_class.new(princ)
|
|
187
|
+
c = described_class.new(principal: princ)
|
|
144
188
|
c.destroy
|
|
145
189
|
expect { c.default_name }.to raise_error(Kerberos::Krb5::Exception)
|
|
146
190
|
end
|
|
191
|
+
|
|
147
192
|
it 'does not accept arguments' do
|
|
148
|
-
c = described_class.new(princ)
|
|
193
|
+
c = described_class.new(principal: princ)
|
|
149
194
|
expect { c.destroy(true) }.to raise_error(ArgumentError)
|
|
150
195
|
end
|
|
151
196
|
end
|
|
152
197
|
|
|
153
198
|
describe '#dup' do
|
|
154
199
|
it 'returns a new cache object with the same properties' do
|
|
155
|
-
c = described_class.new(princ)
|
|
200
|
+
c = described_class.new(principal: princ)
|
|
156
201
|
c2 = c.dup
|
|
157
202
|
expect(c2).to be_a(described_class)
|
|
158
203
|
expect(c2.default_name).to eq(c.default_name)
|
|
@@ -160,23 +205,45 @@ RSpec.describe Kerberos::Krb5::CredentialsCache do
|
|
|
160
205
|
end
|
|
161
206
|
|
|
162
207
|
it 'closing original does not affect duplicate' do
|
|
163
|
-
c = described_class.new(princ)
|
|
208
|
+
c = described_class.new(principal: princ)
|
|
164
209
|
c2 = c.dup
|
|
165
210
|
c.close
|
|
166
211
|
expect { c2.default_name }.not_to raise_error
|
|
167
212
|
end
|
|
168
213
|
|
|
169
214
|
it 'closing duplicate does not affect original' do
|
|
170
|
-
c = described_class.new(princ)
|
|
215
|
+
c = described_class.new(principal: princ)
|
|
171
216
|
c2 = c.dup
|
|
172
217
|
c2.close
|
|
173
218
|
expect { c.default_name }.not_to raise_error
|
|
174
219
|
end
|
|
175
220
|
|
|
176
221
|
it 'raises when duping closed cache' do
|
|
177
|
-
c = described_class.new(princ)
|
|
222
|
+
c = described_class.new(principal: princ)
|
|
178
223
|
c.close
|
|
179
224
|
expect { c.dup }.to raise_error(Kerberos::Krb5::Exception)
|
|
180
225
|
end
|
|
181
226
|
end
|
|
227
|
+
|
|
228
|
+
describe '#full_name' do
|
|
229
|
+
it 'returns a string including the type prefix' do
|
|
230
|
+
cc = described_class.new(principal: princ)
|
|
231
|
+
name = cc.full_name
|
|
232
|
+
expect(name).to be_a(String)
|
|
233
|
+
expect(name).to match(/\A\w+:/)
|
|
234
|
+
cc.close
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it 'includes FILE: for a file-based cache' do
|
|
238
|
+
cc = described_class.new(principal: princ, cache_name: cfile)
|
|
239
|
+
expect(cc.full_name).to start_with('FILE:')
|
|
240
|
+
cc.close
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it 'raises when the context is closed' do
|
|
244
|
+
cc = described_class.new(principal: princ)
|
|
245
|
+
cc.close
|
|
246
|
+
expect { cc.full_name }.to raise_error(Kerberos::Krb5::Exception)
|
|
247
|
+
end
|
|
248
|
+
end
|
|
182
249
|
end
|