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.
data/spec/policy_spec.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # spec/policy_spec.rb
2
2
  # RSpec tests for Kerberos::Kadm5::Policy
3
3
 
4
- require 'rkerberos'
4
+ require 'spec_helper'
5
5
 
6
- RSpec.describe Kerberos::Kadm5::Policy do
7
- subject(:policy) { described_class.new(name: 'test', max_life: 10000) }
6
+ RSpec.describe 'Kerberos::Kadm5::Policy', :kadm5 do
7
+ subject(:klass){ Kerberos::Kadm5::Policy }
8
+ let(:policy) { klass.new(name: 'test', max_life: 10000) }
8
9
 
9
10
  describe 'name' do
10
11
  it 'responds to policy' do
@@ -15,10 +16,14 @@ RSpec.describe Kerberos::Kadm5::Policy do
15
16
  expect(policy.method(:name)).to eq(policy.method(:policy))
16
17
  end
17
18
  it 'must be a string' do
18
- expect { described_class.new(name: 1) }.to raise_error(TypeError)
19
+ expect { klass.new(name: 1) }.to raise_error(TypeError)
19
20
  end
20
21
  it 'must be present' do
21
- expect { described_class.new(max_life: 10000) }.to raise_error(ArgumentError)
22
+ expect { klass.new(max_life: 10000) }.to raise_error(ArgumentError)
23
+ end
24
+ it 'rejects positional option hashes and unknown keywords' do
25
+ expect { klass.new({name: 'test'}) }.to raise_error(ArgumentError)
26
+ expect { klass.new(name: 'test', unknown: true) }.to raise_error(ArgumentError, /unknown keyword/)
22
27
  end
23
28
  end
24
29
 
@@ -28,7 +33,7 @@ RSpec.describe Kerberos::Kadm5::Policy do
28
33
  expect { policy.min_life }.not_to raise_error
29
34
  end
30
35
  it 'must be a number if not nil' do
31
- expect { described_class.new(name: 'test', min_life: 'test') }.to raise_error(TypeError)
36
+ expect { klass.new(name: 'test', min_life: 'test') }.to raise_error(TypeError)
32
37
  end
33
38
  end
34
39
 
@@ -38,7 +43,7 @@ RSpec.describe Kerberos::Kadm5::Policy do
38
43
  expect { policy.max_life }.not_to raise_error
39
44
  end
40
45
  it 'must be a number if not nil' do
41
- expect { described_class.new(name: 'test', max_life: 'test') }.to raise_error(TypeError)
46
+ expect { klass.new(name: 'test', max_life: 'test') }.to raise_error(TypeError)
42
47
  end
43
48
  end
44
49
 
@@ -5,12 +5,61 @@ require 'rkerberos'
5
5
 
6
6
  RSpec.describe Kerberos::Krb5::Principal do
7
7
  let(:name) { 'Jon' }
8
- subject(:princ) { described_class.new(name) }
8
+ subject(:princ) { described_class.new(name: name) }
9
9
 
10
10
  describe 'constructor' do
11
- it 'requires a string argument' do
12
- expect { described_class.new(1) }.to raise_error(TypeError)
13
- expect { described_class.new(true) }.to raise_error(TypeError)
11
+ it 'requires name to be a string' do
12
+ expect { described_class.new(name: 1) }.to raise_error(TypeError)
13
+ expect { described_class.new(name: true) }.to raise_error(TypeError)
14
+ end
15
+
16
+ it 'accepts no arguments' do
17
+ expect{ described_class.new }.not_to raise_error
18
+ end
19
+
20
+ it 'works as expected with no name argument' do
21
+ expect(described_class.new.principal).to be_nil
22
+ end
23
+
24
+ it 'rejects positional arguments' do
25
+ expect { described_class.new('Jon') }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it 'accepts a context keyword argument' do
29
+ ctx = Kerberos::Krb5::Context.new
30
+ expect { described_class.new(name: 'Jon', context: ctx) }.not_to raise_error
31
+ end
32
+
33
+ it 'rejects positional option hashes and unknown keywords' do
34
+ expect { described_class.new({name: 'Jon'}) }.to raise_error(ArgumentError)
35
+ expect { described_class.new(unknown: true) }.to raise_error(ArgumentError, /unknown keyword/)
36
+ end
37
+
38
+ it 'uses the same realm when a context is provided' do
39
+ ctx = Kerberos::Krb5::Context.new
40
+ p1 = described_class.new(name: 'Jon')
41
+ p2 = described_class.new(name: 'Jon', context: ctx)
42
+ expect(p2.realm).to eq(p1.realm)
43
+ end
44
+
45
+ it 'raises TypeError for non-Context context argument' do
46
+ expect { described_class.new(name: 'Jon', context: "bad") }.to raise_error(TypeError)
47
+ end
48
+
49
+ it 'raises error for a closed context' do
50
+ ctx = Kerberos::Krb5::Context.new
51
+ ctx.close
52
+ expect { described_class.new(name: 'Jon', context: ctx) }.to raise_error(Kerberos::Krb5::Exception)
53
+ end
54
+ end
55
+
56
+ describe '#realm' do
57
+ it 'returns the expected value' do
58
+ expect(subject.realm).to eq('EXAMPLE.COM')
59
+ end
60
+
61
+ it 'raises an error if no name was provided' do
62
+ expect{ described_class.new.realm }.to raise_error(Kerberos::Krb5::Exception, /no principal/)
14
63
  end
15
64
  end
16
65
 
@@ -65,4 +114,53 @@ RSpec.describe Kerberos::Krb5::Principal do
65
114
  expect { princ.mod_date }.not_to raise_error
66
115
  end
67
116
  end
117
+
118
+ describe '#principal_type' do
119
+ it 'returns an integer for a named principal' do
120
+ p = described_class.new(name: 'user@EXAMPLE.COM')
121
+ expect(p.principal_type).to be_a(Integer)
122
+ end
123
+
124
+ it 'returns KRB5_NT_PRINCIPAL (1) for a simple name' do
125
+ p = described_class.new(name: 'user@EXAMPLE.COM')
126
+ expect(p.principal_type).to eq(1)
127
+ end
128
+
129
+ it 'raises an error when no principal has been established' do
130
+ p = described_class.new
131
+ expect { p.principal_type }.to raise_error(Kerberos::Krb5::Exception, /no principal/)
132
+ end
133
+ end
134
+
135
+ describe '#components' do
136
+ it 'responds to components' do
137
+ expect(princ).to respond_to(:components)
138
+ end
139
+
140
+ it 'returns an array of strings' do
141
+ result = princ.components
142
+ expect(result).to be_a(Array)
143
+ result.each { |c| expect(c).to be_a(String) }
144
+ end
145
+
146
+ it 'returns one component for a simple principal' do
147
+ p = described_class.new(name: 'user@EXAMPLE.COM')
148
+ expect(p.components).to eq(['user'])
149
+ end
150
+
151
+ it 'returns multiple components for a compound principal' do
152
+ p = described_class.new(name: 'admin/instance@EXAMPLE.COM')
153
+ expect(p.components).to eq(['admin', 'instance'])
154
+ end
155
+
156
+ it 'returns three components for a three-part principal' do
157
+ p = described_class.new(name: 'a/b/c@EXAMPLE.COM')
158
+ expect(p.components).to eq(['a', 'b', 'c'])
159
+ end
160
+
161
+ it 'raises an error when no principal has been established' do
162
+ p = described_class.new
163
+ expect { p.components }.to raise_error(Kerberos::Krb5::Exception, /no principal/)
164
+ end
165
+ end
68
166
  end
@@ -0,0 +1,34 @@
1
+ require 'rkerberos'
2
+ require 'rspec'
3
+ require 'etc'
4
+ require 'tmpdir'
5
+
6
+ RSpec.configure do |config|
7
+ config.filter_run_excluding :kadm5 => true unless defined?(Kerberos::Kadm5::Config)
8
+ config.filter_run_excluding :unix => true if File::ALT_SEPARATOR
9
+
10
+ krb5_conf = ENV['KRB5_CONFIG']
11
+ krb5_cc_name = ENV['KRB5CCNAME']
12
+ login = Etc.getlogin || ENV['USER'] || (Etc.getpwuid(Process.uid).name rescue nil)
13
+
14
+ if File::ALT_SEPARATOR
15
+ krb5_conf ||= 'C:\\ProgramData\\MIT\\Kerberos5\\krb5.ini'
16
+ krb5_cc_name ||= File.join(ENV['USERPROFILE'], 'krb5cache')
17
+ else
18
+ krb5_conf ||= '/etc/krb5.conf'
19
+ krb5_cc_name ||= File.join(Dir.tmpdir, "krb5cc_#{Etc.getpwnam(login).uid}")
20
+ end
21
+
22
+ config.add_setting :krb5_conf
23
+ config.krb5_conf = krb5_conf
24
+
25
+ config.add_setting :krb5_cc_name
26
+ config.krb5_cc_name = krb5_cc_name
27
+
28
+ config.add_setting :login
29
+ config.login = login
30
+
31
+ unless File.exist?(krb5_conf)
32
+ config.filter_run_excluding :krb5_config => true
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rkerberos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Berger
@@ -66,6 +66,7 @@ extensions:
66
66
  extra_rdoc_files: []
67
67
  files:
68
68
  - CHANGES.md
69
+ - EXAMPLES.md
69
70
  - Gemfile
70
71
  - LICENSE
71
72
  - MANIFEST.md
@@ -92,17 +93,18 @@ files:
92
93
  - spec/krb5_spec.rb
93
94
  - spec/policy_spec.rb
94
95
  - spec/principal_spec.rb
95
- homepage: http://github.com/rkerberos/rkerberos
96
+ - spec/spec_helper.rb
97
+ homepage: https://github.com/rkerberos/rkerberos
96
98
  licenses:
97
99
  - Artistic-2.0
98
100
  metadata:
99
- homepage_uri: https://github.com/rkerberos/rkerberos
100
101
  bug_tracker_uri: https://github.com/rkerberos/rkerberos/issues
101
- changelog_uri: https://github.com/rkerberos/rkerberos/blob/main/CHANGES.md
102
+ changelog_uri: https://github.com/rkerberos/rkerberos/blob/master/CHANGES.md
102
103
  documentation_uri: https://github.com/rkerberos/rkerberos/wiki
104
+ homepage_uri: https://github.com/rkerberos/rkerberos
103
105
  source_code_uri: https://github.com/rkerberos/rkerberos
104
106
  wiki_uri: https://github.com/rkerberos/rkerberos/wiki
105
- github_repo: https://github.com/djberg96/rkerberos
107
+ github_repo: https://github.com/rkerberos/rkerberos
106
108
  funding_uri: https://github.com/sponsors/rkerberos
107
109
  rubygems_mfa_required: 'true'
108
110
  rdoc_options: []
@@ -112,16 +114,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
114
  requirements:
113
115
  - - ">="
114
116
  - !ruby/object:Gem::Version
115
- version: '0'
117
+ version: '3.2'
116
118
  required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  requirements:
118
120
  - - ">="
119
121
  - !ruby/object:Gem::Version
120
122
  version: '0'
121
123
  requirements: []
122
- rubygems_version: 4.0.6
124
+ rubygems_version: 4.0.18
123
125
  specification_version: 4
124
- summary: A Ruby interface for the the Kerberos library
126
+ summary: A Ruby interface for the Kerberos library
125
127
  test_files:
126
128
  - spec/config_spec.rb
127
129
  - spec/context_spec.rb