rkerberos 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10c43a653634532f7c52f8156f9ea2c9b5646d9bdff60866f8dde301c1abe5e7
4
- data.tar.gz: 99021863b149758d3231938481736878027ad99ef8b4056d3d994e0b0a8dbffb
3
+ metadata.gz: 71575b32bb628b8425101d837de9c86ce1dd5e865a5db93462457266c8eb4d2c
4
+ data.tar.gz: 99128f7462ed48175619b224d838f2dd00b7d7f972963530c1276037fe299792
5
5
  SHA512:
6
- metadata.gz: c74926903cdbbcafe0e756189b0e5b53308fc30f4808d090d8091e92941c28f9c7e4629f61c9fb30df130990574bec809f42cfccee9d75d9b697e27e5654889f
7
- data.tar.gz: 798be63f34c776a54d1ea54556edc36d965ac0149b7a04414f37b16db3439f8ea1dc8ae7d0f64a0c826c3f80d7cdea0818f5c519a2a77bac0495fa3cb4a44317
6
+ metadata.gz: d90e4d248f40ae3cd13d02febfe71cd92e0dbc4712f37326444eff8368e5326a55980424263f30d8983a1ddd674b948034cbad0c3ce3e6606649e72feb77ca57
7
+ data.tar.gz: aa5bd082185a5e8b11b4d50d9e58e3fc76f954b9694d5f00aa5c53e4aeca5739c737a4c4477cc028b374391b108b4a4d166c25ce557b4a39eee39f5a1758ad16
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.2.3 - 8-Mar-2026
2
+ * All Kadm5 related classes are skipped if not found.
3
+ * Several updates to the spec helper that mainly revolved around supporting
4
+ MS Windows and/or skipping specs when Kadm5 classes aren't found.
5
+ * More potential memory issues addressed, mainly stuff that only happened
6
+ on an error path.
7
+
1
8
  # 0.2.2 - 3-Mar-2026
2
9
  * Added custom .dup methods for CredentialsCache and Keytab.
3
10
  * Added the keytab_name and keytab_type methods to Keytab.
@@ -267,6 +267,10 @@ static VALUE rkrb5_ccache_destroy(VALUE self){
267
267
  if(ptr->ctx)
268
268
  krb5_free_context(ptr->ctx);
269
269
 
270
+ ptr->ccache = NULL;
271
+ ptr->ctx = NULL;
272
+ ptr->principal = NULL;
273
+
270
274
  rb_raise(cKrb5Exception, "krb5_cc_destroy: %s", error_message(kerror));
271
275
  }
272
276
  }
@@ -1,3 +1,4 @@
1
+ #ifdef HAVE_KADM5_ADMIN_H
1
2
  #include <rkerberos.h>
2
3
 
3
4
  VALUE cKadm5Config;
@@ -8,9 +9,10 @@ VALUE cKeySalt;
8
9
  static void rkadm5_config_typed_free(void *ptr) {
9
10
  if (!ptr) return;
10
11
  RUBY_KADM5_CONFIG *c = (RUBY_KADM5_CONFIG *)ptr;
11
- kadm5_free_config_params(c->ctx, &c->config);
12
- if (c->ctx)
12
+ if (c->ctx) {
13
+ kadm5_free_config_params(c->ctx, &c->config);
13
14
  krb5_free_context(c->ctx);
15
+ }
14
16
  free(c);
15
17
  }
16
18
 
@@ -332,4 +334,5 @@ void Init_config(void){
332
334
  cKeySalt = rb_define_class_under(cKadm5, "KeySalt", rb_cObject);
333
335
  rb_define_attr(cKeySalt, "enctype", 1, 0);
334
336
  rb_define_attr(cKeySalt, "salttype", 1, 0);
335
- }
337
+ }
338
+ #endif
@@ -61,6 +61,8 @@ static VALUE rkrb5_context_close(VALUE self){
61
61
  *
62
62
  * :secure => true|false # Use config files only, ignore env variables
63
63
  * :profile => '/path/to/krb5.conf' # Use the specified profile file
64
+ *
65
+ * Note that the profile option may not be supported on your platform.
64
66
  */
65
67
  static VALUE rkrb5_context_initialize(int argc, VALUE *argv, VALUE self){
66
68
  RUBY_KRB5_CONTEXT* ptr;
@@ -92,6 +94,9 @@ static VALUE rkrb5_context_initialize(int argc, VALUE *argv, VALUE self){
92
94
  * is used when the :secure option is truthy.
93
95
  */
94
96
  if (!NIL_P(v_profile)){
97
+ #ifndef HAVE_PROFILE_INIT_PATH
98
+ rb_raise(rb_eArgError, "profile option not supported on this platform");
99
+ #else
95
100
  Check_Type(v_profile, T_STRING);
96
101
 
97
102
  const char *profile_path = StringValueCStr(v_profile);
@@ -110,6 +115,7 @@ static VALUE rkrb5_context_initialize(int argc, VALUE *argv, VALUE self){
110
115
  rb_raise(cKrb5Exception, "krb5_init_context_profile: %s", error_message(kerror));
111
116
 
112
117
  return self;
118
+ #endif
113
119
  }
114
120
 
115
121
  // No profile given, choose secure or normal init.
@@ -14,8 +14,19 @@ else
14
14
  else
15
15
  dir_config('rkerberos', '/usr/local')
16
16
  end
17
+
18
+ if File::ALT_SEPARATOR
19
+ kfw_dir = ENV['KRB5_DIR'] || 'C:/Program Files/MIT/Kerberos'
20
+ kfw_inc = ENV['KRB5_INCLUDE'] || File.join(kfw_dir, 'include')
21
+ kfw_lib = ENV['KRB5_LIB'] || File.join(kfw_dir, 'lib')
22
+ $INCFLAGS << " -I\"#{kfw_inc}\""
23
+ $LDFLAGS << " -L\"#{kfw_lib}\""
24
+ end
25
+
17
26
  have_header('krb5.h')
18
- have_library('krb5')
27
+
28
+ have_library('krb5') || have_library('krb5_64')
29
+ have_library('comerr') || have_library('comerr64')
19
30
  end
20
31
 
21
32
  pkg_config('com_err') || have_library('com_err')
@@ -26,8 +37,10 @@ end
26
37
 
27
38
  if pkg_config('kdb5') || have_library('kdb5')
28
39
  have_header('kdb.h')
29
- else
30
- raise 'kdb5 library not found'
40
+ end
41
+
42
+ if have_header('profile.h')
43
+ have_func('profile_init_path')
31
44
  end
32
45
 
33
46
  create_makefile('rkerberos')
@@ -9,6 +9,7 @@ VALUE cKadm5PrincipalNotFoundException;
9
9
  // Prototype
10
10
  static VALUE rkadm5_close(VALUE);
11
11
  static void free_tl_data(krb5_tl_data *);
12
+ static void free_db_args(char**);
12
13
  char** parse_db_args(VALUE v_db_args);
13
14
  void add_db_args(kadm5_principal_ent_rec*, char**);
14
15
  void add_tl_data(krb5_int16 *, krb5_tl_data **,
@@ -25,7 +26,7 @@ static void rkadm5_typed_free(void *ptr) {
25
26
  krb5_free_principal(k->ctx, k->princ);
26
27
  if (k->ctx)
27
28
  krb5_free_context(k->ctx);
28
- free(k->db_args);
29
+ free_db_args(k->db_args);
29
30
  free(k);
30
31
  }
31
32
 
@@ -314,7 +315,7 @@ static VALUE rkadm5_create_principal(int argc, VALUE* argv, VALUE self){
314
315
 
315
316
  db_args = parse_db_args(v_db_args);
316
317
  add_db_args(&princ, db_args);
317
- free(db_args);
318
+ free_db_args(db_args);
318
319
 
319
320
  if(!ptr->ctx)
320
321
  rb_raise(cKadm5Exception, "no context has been established");
@@ -398,7 +399,7 @@ static VALUE rkadm5_close(VALUE self){
398
399
  if(ptr->ctx)
399
400
  krb5_free_context(ptr->ctx);
400
401
 
401
- free(ptr->db_args);
402
+ free_db_args(ptr->db_args);
402
403
 
403
404
  ptr->db_args = NULL;
404
405
  ptr->ctx = NULL;
@@ -446,8 +447,10 @@ static VALUE create_principal_from_entry(VALUE v_name, RUBY_KADM5* ptr, kadm5_pr
446
447
  char* mod_name;
447
448
  kerror = krb5_unparse_name(ptr->ctx, ent->mod_name, &mod_name);
448
449
 
449
- if(kerror)
450
+ if(kerror){
451
+ kadm5_free_principal_ent(ptr->handle, ent);
450
452
  rb_raise(cKadm5Exception, "krb5_unparse_name: %s", error_message(kerror));
453
+ }
451
454
 
452
455
  rb_iv_set(v_principal, "@mod_name", rb_str_new2(mod_name));
453
456
  krb5_free_unparsed_name(ptr->ctx, mod_name);
@@ -459,6 +462,8 @@ static VALUE create_principal_from_entry(VALUE v_name, RUBY_KADM5* ptr, kadm5_pr
459
462
  if(ent->policy)
460
463
  rb_iv_set(v_principal, "@policy", rb_str_new2(ent->policy));
461
464
 
465
+ kadm5_free_principal_ent(ptr->handle, ent);
466
+
462
467
  return v_principal;
463
468
  }
464
469
 
@@ -518,7 +523,6 @@ static VALUE rkadm5_find_principal(VALUE self, VALUE v_user){
518
523
  }
519
524
  else{
520
525
  v_principal = create_principal_from_entry(v_user, ptr, &ent);
521
- kadm5_free_principal_ent(ptr->handle, &ent);
522
526
  }
523
527
 
524
528
  return v_principal;
@@ -580,8 +584,6 @@ static VALUE rkadm5_get_principal(VALUE self, VALUE v_user){
580
584
 
581
585
  v_principal = create_principal_from_entry(v_user, ptr, &ent);
582
586
 
583
- kadm5_free_principal_ent(ptr->handle, &ent);
584
-
585
587
  return v_principal;
586
588
  }
587
589
 
@@ -1039,7 +1041,7 @@ char** parse_db_args(VALUE v_db_args){
1039
1041
  switch(TYPE(v_db_args)){
1040
1042
  case T_STRING:
1041
1043
  db_args = (char **) malloc(2 * sizeof(char *));
1042
- db_args[0] = StringValueCStr(v_db_args);
1044
+ db_args[0] = strdup(StringValueCStr(v_db_args));
1043
1045
  db_args[1] = NULL;
1044
1046
  break;
1045
1047
  case T_ARRAY:
@@ -1049,7 +1051,7 @@ char** parse_db_args(VALUE v_db_args){
1049
1051
  for(long i = 0; i < array_length; ++i){
1050
1052
  VALUE elem = rb_ary_entry(v_db_args, i);
1051
1053
  Check_Type(elem, T_STRING);
1052
- db_args[i] = StringValueCStr(elem);
1054
+ db_args[i] = strdup(StringValueCStr(elem));
1053
1055
  }
1054
1056
  db_args[array_length] = NULL;
1055
1057
  break;
@@ -1062,6 +1064,16 @@ char** parse_db_args(VALUE v_db_args){
1062
1064
  return db_args;
1063
1065
  }
1064
1066
 
1067
+ /**
1068
+ * Free a NULL-terminated array of strings returned by parse_db_args.
1069
+ */
1070
+ static void free_db_args(char** db_args){
1071
+ if(!db_args) return;
1072
+ for(int i = 0; db_args[i] != NULL; i++)
1073
+ free(db_args[i]);
1074
+ free(db_args);
1075
+ }
1076
+
1065
1077
  /**
1066
1078
  * Add parsed db-args to principal entry
1067
1079
  */
@@ -51,7 +51,12 @@ static VALUE rkrb5_keytab_each_body(VALUE arg){
51
51
  VALUE v_kt_entry;
52
52
 
53
53
  while((kerror = krb5_kt_next_entry(ea->ctx, ea->keytab, &entry, &ea->cursor)) == 0){
54
- krb5_unparse_name(ea->ctx, entry.principal, &principal);
54
+ kerror = krb5_unparse_name(ea->ctx, entry.principal, &principal);
55
+
56
+ if(kerror){
57
+ krb5_kt_free_entry(ea->ctx, &entry);
58
+ rb_raise(cKrb5Exception, "krb5_unparse_name: %s", error_message(kerror));
59
+ }
55
60
 
56
61
  v_kt_entry = rb_class_new_instance(0, NULL, cKrb5KtEntry);
57
62
 
@@ -503,7 +508,12 @@ static VALUE rkrb5_s_keytab_foreach_body(VALUE arg){
503
508
  VALUE v_kt_entry;
504
509
 
505
510
  while((kerror = krb5_kt_next_entry(fa->ctx, fa->keytab, &entry, &fa->cursor)) == 0){
506
- krb5_unparse_name(fa->ctx, entry.principal, &principal);
511
+ kerror = krb5_unparse_name(fa->ctx, entry.principal, &principal);
512
+
513
+ if(kerror){
514
+ krb5_kt_free_entry(fa->ctx, &entry);
515
+ rb_raise(cKrb5Exception, "krb5_unparse_name: %s", error_message(kerror));
516
+ }
507
517
 
508
518
  v_kt_entry = rb_class_new_instance(0, NULL, cKrb5KtEntry);
509
519
 
@@ -63,7 +63,8 @@ static VALUE rkrb5_kt_entry_inspect(VALUE self){
63
63
 
64
64
  rb_str_buf_cat2(v_str, "key=");
65
65
  rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@key")));
66
- rb_str_buf_cat2(v_str, " ");
66
+
67
+ rb_str_buf_cat2(v_str, ">");
67
68
 
68
69
  return v_str;
69
70
  }
@@ -49,22 +49,30 @@ static VALUE rkrb5_princ_allocate(VALUE klass){
49
49
  static VALUE rkrb5_princ_initialize(VALUE self, VALUE v_name){
50
50
  RUBY_KRB5_PRINC* ptr;
51
51
  krb5_error_code kerror;
52
+
52
53
  TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr);
54
+
53
55
  kerror = krb5_init_context(&ptr->ctx);
56
+
54
57
  if(kerror)
55
58
  rb_raise(cKrb5Exception, "krb5_init_context failed: %s", error_message(kerror));
59
+
56
60
  if(NIL_P(v_name)){
57
61
  rb_iv_set(self, "@principal", Qnil);
58
62
  }
59
63
  else{
60
64
  char* name;
61
65
  Check_Type(v_name, T_STRING);
66
+
62
67
  name = StringValueCStr(v_name);
63
68
  kerror = krb5_parse_name(ptr->ctx, name, &ptr->principal);
69
+
64
70
  if(kerror)
65
71
  rb_raise(cKrb5Exception, "krb5_parse_name failed: %s", error_message(kerror));
72
+
66
73
  rb_iv_set(self, "@principal", v_name);
67
74
  }
75
+
68
76
  rb_iv_set(self, "@attributes", Qnil);
69
77
  rb_iv_set(self, "@aux_attributes", Qnil);
70
78
  rb_iv_set(self, "@expire_time", Qnil);
@@ -79,8 +87,10 @@ static VALUE rkrb5_princ_initialize(VALUE self, VALUE v_name){
79
87
  rb_iv_set(self, "@password_expiration", Qnil);
80
88
  rb_iv_set(self, "@policy", Qnil);
81
89
  rb_iv_set(self, "@kvno", Qnil);
90
+
82
91
  if(rb_block_given_p())
83
92
  rb_yield(self);
93
+
84
94
  return self;
85
95
  }
86
96
 
@@ -92,7 +102,12 @@ static VALUE rkrb5_princ_initialize(VALUE self, VALUE v_name){
92
102
  */
93
103
  static VALUE rkrb5_princ_get_realm(VALUE self){
94
104
  RUBY_KRB5_PRINC* ptr;
105
+
95
106
  TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr);
107
+
108
+ if(!ptr->principal)
109
+ rb_raise(cKrb5Exception, "no principal has been established");
110
+
96
111
  return rb_str_new2(krb5_princ_realm(ptr->ctx, ptr->principal)->data);
97
112
  }
98
113
 
@@ -104,9 +119,16 @@ static VALUE rkrb5_princ_get_realm(VALUE self){
104
119
  */
105
120
  static VALUE rkrb5_princ_set_realm(VALUE self, VALUE v_realm){
106
121
  RUBY_KRB5_PRINC* ptr;
122
+
107
123
  TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr);
124
+
125
+ if(!ptr->principal)
126
+ rb_raise(cKrb5Exception, "no principal has been established");
127
+
108
128
  Check_Type(v_realm, T_STRING);
129
+
109
130
  krb5_set_principal_realm(ptr->ctx, ptr->principal, StringValueCStr(v_realm));
131
+
110
132
  return v_realm;
111
133
  }
112
134
 
@@ -120,10 +142,16 @@ static VALUE rkrb5_princ_equal(VALUE self, VALUE v_other){
120
142
  RUBY_KRB5_PRINC* ptr1;
121
143
  RUBY_KRB5_PRINC* ptr2;
122
144
  VALUE v_bool = Qfalse;
145
+
123
146
  TypedData_Get_Struct(self, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr1);
124
147
  TypedData_Get_Struct(v_other, RUBY_KRB5_PRINC, &rkrb5_princ_data_type, ptr2);
148
+
149
+ if(!ptr1->principal || !ptr2->principal)
150
+ return Qfalse;
151
+
125
152
  if(krb5_principal_compare(ptr1->ctx, ptr1->principal, ptr2->principal))
126
153
  v_bool = Qtrue;
154
+
127
155
  return v_bool;
128
156
  }
129
157
 
@@ -181,18 +181,27 @@ static VALUE rkrb5_get_init_creds_keytab(int argc, VALUE* argv, VALUE self){
181
181
  krb5_free_cred_contents(ptr->ctx, &ptr->creds);
182
182
  memset(&ptr->creds, 0, sizeof(ptr->creds));
183
183
 
184
+ rb_scan_args(argc, argv, "04", &v_user, &v_keytab_name, &v_service, &v_ccache);
185
+
186
+ // Validate argument types before allocating opt, so type errors don't leak it.
187
+ if(!NIL_P(v_user))
188
+ Check_Type(v_user, T_STRING);
189
+
190
+ if(!NIL_P(v_keytab_name))
191
+ Check_Type(v_keytab_name, T_STRING);
192
+
193
+ if(!NIL_P(v_service))
194
+ Check_Type(v_service, T_STRING);
195
+
184
196
  kerror = krb5_get_init_creds_opt_alloc(ptr->ctx, &opt);
185
197
  if(kerror)
186
198
  rb_raise(cKrb5Exception, "krb5_get_init_creds_opt_alloc: %s", error_message(kerror));
187
199
 
188
- rb_scan_args(argc, argv, "04", &v_user, &v_keytab_name, &v_service, &v_ccache);
189
-
190
200
  // We need the service information for later.
191
201
  if(NIL_P(v_service)){
192
202
  service = NULL;
193
203
  }
194
204
  else{
195
- Check_Type(v_service, T_STRING);
196
205
  service = StringValueCStr(v_service);
197
206
  }
198
207
 
@@ -212,7 +221,6 @@ static VALUE rkrb5_get_init_creds_keytab(int argc, VALUE* argv, VALUE self){
212
221
  }
213
222
  }
214
223
  else{
215
- Check_Type(v_user, T_STRING);
216
224
  user = StringValueCStr(v_user);
217
225
 
218
226
  kerror = krb5_parse_name(ptr->ctx, user, &ptr->princ);
@@ -233,7 +241,6 @@ static VALUE rkrb5_get_init_creds_keytab(int argc, VALUE* argv, VALUE self){
233
241
  }
234
242
  }
235
243
  else{
236
- Check_Type(v_keytab_name, T_STRING);
237
244
  strncpy(keytab_name, StringValueCStr(v_keytab_name), MAX_KEYTAB_NAME_LEN - 1);
238
245
  keytab_name[MAX_KEYTAB_NAME_LEN - 1] = '\0';
239
246
  }
@@ -678,8 +685,10 @@ static VALUE rkrb5_get_permitted_enctypes(VALUE self){
678
685
  v_enctypes = rb_hash_new();
679
686
 
680
687
  for(i = 0; ktypes[i]; i++){
681
- if(krb5_enctype_to_string(ktypes[i], encoding, 128)){
682
- rb_raise(cKrb5Exception, "krb5_enctype_to_string: %s", error_message(kerror));
688
+ krb5_error_code enc_err = krb5_enctype_to_string(ktypes[i], encoding, 128);
689
+ if(enc_err){
690
+ krb5_free_enctypes(ptr->ctx, ktypes);
691
+ rb_raise(cKrb5Exception, "krb5_enctype_to_string: %s", error_message(enc_err));
683
692
  }
684
693
  rb_hash_aset(v_enctypes, INT2FIX(ktypes[i]), rb_str_new2(encoding));
685
694
  }
@@ -799,8 +808,8 @@ void Init_rkerberos(void){
799
808
  rb_define_alias(cKrb5, "default_realm", "get_default_realm");
800
809
  rb_define_alias(cKrb5, "default_principal", "get_default_principal");
801
810
 
802
- /* 0.2.1: The version of the custom rkerberos library */
803
- rb_define_const(cKrb5, "VERSION", rb_str_new2("0.2.2"));
811
+ /* 0.2.3: The version of the custom rkerberos library */
812
+ rb_define_const(cKrb5, "VERSION", rb_str_new2("0.2.3"));
804
813
 
805
814
  // Encoding type constants
806
815
 
data/rkerberos.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'rkerberos'
5
- spec.version = '0.2.2'
5
+ spec.version = '0.2.3'
6
6
  spec.authors = ['Daniel Berger', 'Dominic Cleal', 'Simon Levermann']
7
7
  spec.license = 'Artistic-2.0'
8
8
  spec.email = ['djberg96@gmail.com', 'dominic@cleal.org', 'simon-rubygems@slevermann.de']
data/spec/config_spec.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # spec/config_spec.rb
2
2
  # RSpec tests for Kerberos::Kadm5::Config
3
3
 
4
- require 'rkerberos'
4
+ require 'spec_helper'
5
5
 
6
- RSpec.describe Kerberos::Kadm5::Config do
7
- subject(:config) { described_class.new }
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
@@ -14,6 +15,7 @@ RSpec.describe Kerberos::Kadm5::Config do
14
15
  it 'responds to realm' do
15
16
  expect(config).to respond_to(:realm)
16
17
  end
18
+
17
19
  it 'returns a String' do
18
20
  expect(config.realm).to be_a(String)
19
21
  end
@@ -23,6 +25,7 @@ RSpec.describe Kerberos::Kadm5::Config do
23
25
  it 'responds to kadmind_port' do
24
26
  expect(config).to respond_to(:kadmind_port)
25
27
  end
28
+
26
29
  it 'returns an Integer' do
27
30
  expect(config.kadmind_port).to be_a(Integer)
28
31
  end
@@ -32,6 +35,7 @@ RSpec.describe Kerberos::Kadm5::Config do
32
35
  it 'responds to kpasswd_port' do
33
36
  expect(config).to respond_to(:kpasswd_port)
34
37
  end
38
+
35
39
  it 'returns an Integer' do
36
40
  expect(config.kpasswd_port).to be_a(Integer)
37
41
  end
@@ -41,6 +45,7 @@ RSpec.describe Kerberos::Kadm5::Config do
41
45
  it 'responds to admin_server' do
42
46
  expect(config).to respond_to(:admin_server)
43
47
  end
48
+
44
49
  it 'returns a String' do
45
50
  expect(config.admin_server).to be_a(String)
46
51
  end
@@ -50,6 +55,7 @@ RSpec.describe Kerberos::Kadm5::Config do
50
55
  it 'responds to acl_file' do
51
56
  expect(config).to respond_to(:acl_file)
52
57
  end
58
+
53
59
  it 'returns a String' do
54
60
  expect(config.acl_file).to be_a(String)
55
61
  end
@@ -59,6 +65,7 @@ RSpec.describe Kerberos::Kadm5::Config do
59
65
  it 'responds to dict_file' do
60
66
  expect(config).to respond_to(:dict_file)
61
67
  end
68
+
62
69
  it 'returns a String or nil' do
63
70
  expect([String, NilClass]).to include(config.dict_file.class)
64
71
  end
@@ -68,6 +75,7 @@ RSpec.describe Kerberos::Kadm5::Config do
68
75
  it 'responds to stash_file' do
69
76
  expect(config).to respond_to(:stash_file)
70
77
  end
78
+
71
79
  it 'returns a String or nil' do
72
80
  expect([String, NilClass]).to include(config.stash_file.class)
73
81
  end
@@ -77,6 +85,7 @@ RSpec.describe Kerberos::Kadm5::Config do
77
85
  it 'responds to mkey_name' do
78
86
  expect(config).to respond_to(:mkey_name)
79
87
  end
88
+
80
89
  it 'returns a String or nil' do
81
90
  expect([String, NilClass]).to include(config.mkey_name.class)
82
91
  end
@@ -86,6 +95,7 @@ RSpec.describe Kerberos::Kadm5::Config do
86
95
  it 'responds to mkey_from_kbd' do
87
96
  expect(config).to respond_to(:mkey_from_kbd)
88
97
  end
98
+
89
99
  it 'returns an Integer or nil' do
90
100
  expect([Integer, NilClass]).to include(config.mkey_from_kbd.class)
91
101
  end
@@ -95,6 +105,7 @@ RSpec.describe Kerberos::Kadm5::Config do
95
105
  it 'responds to enctype' do
96
106
  expect(config).to respond_to(:enctype)
97
107
  end
108
+
98
109
  it 'returns an Integer' do
99
110
  expect(config.enctype).to be_a(Integer)
100
111
  end
@@ -104,6 +115,7 @@ RSpec.describe Kerberos::Kadm5::Config do
104
115
  it 'responds to max_life' do
105
116
  expect(config).to respond_to(:max_life)
106
117
  end
118
+
107
119
  it 'returns an Integer' do
108
120
  expect(config.max_life).to be_a(Integer)
109
121
  end
@@ -113,6 +125,7 @@ RSpec.describe Kerberos::Kadm5::Config do
113
125
  it 'responds to max_rlife' do
114
126
  expect(config).to respond_to(:max_rlife)
115
127
  end
128
+
116
129
  it 'returns an Integer' do
117
130
  expect(config.max_rlife).to be_a(Integer)
118
131
  end
@@ -122,6 +135,7 @@ RSpec.describe Kerberos::Kadm5::Config do
122
135
  it 'responds to expiration' do
123
136
  expect(config).to respond_to(:expiration)
124
137
  end
138
+
125
139
  it 'returns a Time or nil' do
126
140
  expect([Time, NilClass]).to include(config.expiration.class)
127
141
  end
@@ -131,6 +145,7 @@ RSpec.describe Kerberos::Kadm5::Config do
131
145
  it 'responds to kvno' do
132
146
  expect(config).to respond_to(:kvno)
133
147
  end
148
+
134
149
  it 'returns an Integer or nil' do
135
150
  expect([Integer, NilClass]).to include(config.kvno.class)
136
151
  end
@@ -140,6 +155,7 @@ RSpec.describe Kerberos::Kadm5::Config do
140
155
  it 'responds to iprop_enabled' do
141
156
  expect(config).to respond_to(:iprop_enabled)
142
157
  end
158
+
143
159
  it 'returns a boolean' do
144
160
  expect(!!config.iprop_enabled == config.iprop_enabled).to be true
145
161
  end
@@ -149,6 +165,7 @@ RSpec.describe Kerberos::Kadm5::Config do
149
165
  it 'responds to iprop_logfile' do
150
166
  expect(config).to respond_to(:iprop_logfile)
151
167
  end
168
+
152
169
  it 'returns a String' do
153
170
  expect(config.iprop_logfile).to be_a(String)
154
171
  end
@@ -158,6 +175,7 @@ RSpec.describe Kerberos::Kadm5::Config do
158
175
  it 'responds to iprop_poll_time' do
159
176
  expect(config).to respond_to(:iprop_poll_time)
160
177
  end
178
+
161
179
  it 'returns an Integer' do
162
180
  expect(config.iprop_poll_time).to be_a(Integer)
163
181
  end
@@ -167,6 +185,7 @@ RSpec.describe Kerberos::Kadm5::Config do
167
185
  it 'responds to iprop_port' do
168
186
  expect(config).to respond_to(:iprop_port)
169
187
  end
188
+
170
189
  it 'returns an Integer or nil' do
171
190
  expect([Integer, NilClass]).to include(config.iprop_port.class)
172
191
  end
@@ -176,6 +195,7 @@ RSpec.describe Kerberos::Kadm5::Config do
176
195
  it 'responds to num_keysalts' do
177
196
  expect(config).to respond_to(:num_keysalts)
178
197
  end
198
+
179
199
  it 'returns an Integer' do
180
200
  expect(config.num_keysalts).to be_a(Integer)
181
201
  end
@@ -185,9 +205,11 @@ RSpec.describe Kerberos::Kadm5::Config do
185
205
  it 'responds to keysalts' do
186
206
  expect(config).to respond_to(:keysalts)
187
207
  end
208
+
188
209
  it 'returns an Array' do
189
210
  expect(config.keysalts).to be_a(Array)
190
211
  end
212
+
191
213
  it 'contains KeySalt objects if not empty' do
192
214
  unless config.keysalts.empty?
193
215
  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 'rkerberos'
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,10 +44,8 @@ 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)
@@ -1,51 +1,55 @@
1
1
  # spec/credentials_cache_spec.rb
2
2
  # RSpec tests for Kerberos::Krb5::CredentialsCache
3
3
 
4
- require 'rkerberos'
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) { "#{login}@#{realm}" }
15
- let(:cfile) { File.join(Dir.tmpdir, "krb5cc_#{Etc.getpwnam(login).uid}") }
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
- found = true
20
- Open3.popen3('klist') { |_, _, stderr| found = false unless stderr.gets.nil? }
21
- found
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
39
  expect { described_class.new(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
45
  expect { described_class.new(princ, cfile) }.not_to raise_error
44
46
  expect { described_class.new(nil, cfile) }.not_to raise_error
45
47
  end
48
+
46
49
  it 'raises error for non-string argument' do
47
50
  expect { described_class.new(true) }.to raise_error(TypeError)
48
51
  end
52
+
49
53
  it 'accepts only up to two arguments' do
50
54
  expect { described_class.new(princ, cfile, cfile) }.to raise_error(ArgumentError)
51
55
  end
@@ -55,15 +59,18 @@ RSpec.describe Kerberos::Krb5::CredentialsCache do
55
59
  it 'responds to close' do
56
60
  expect(described_class.new(princ)).to respond_to(:close)
57
61
  end
62
+
58
63
  it 'does not delete credentials cache' do
59
64
  c = described_class.new(princ)
60
65
  expect { c.close }.not_to raise_error
61
66
  expect(cache_found?).to be true
62
67
  end
68
+
63
69
  it 'can be called multiple times without error' do
64
70
  c = described_class.new(princ)
65
71
  expect { 3.times { c.close } }.not_to raise_error
66
72
  end
73
+
67
74
  it 'raises error when calling method on closed object' do
68
75
  c = described_class.new(princ)
69
76
  c.close
@@ -77,6 +84,7 @@ RSpec.describe Kerberos::Krb5::CredentialsCache do
77
84
  expect(c).to respond_to(:default_name)
78
85
  expect { c.default_name }.not_to raise_error
79
86
  end
87
+
80
88
  it 'returns a string' do
81
89
  c = described_class.new(princ)
82
90
  expect(c.default_name).to be_a(String)
@@ -94,7 +102,7 @@ RSpec.describe Kerberos::Krb5::CredentialsCache do
94
102
 
95
103
  # cache_name returns the residual portion of the cache name; default_name
96
104
  # may include the type prefix (e.g. "FILE:"). ensure the suffix matches.
97
- expect(c.cache_name).to eq(c.default_name.split(':').last)
105
+ expect(c.cache_name).to eq(c.default_name.split(/\w{2,}:/).last)
98
106
  end
99
107
  end
100
108
 
@@ -112,6 +120,7 @@ RSpec.describe Kerberos::Krb5::CredentialsCache do
112
120
  expect(c).to respond_to(:primary_principal)
113
121
  expect { c.primary_principal }.not_to raise_error
114
122
  end
123
+
115
124
  it 'returns expected results' do
116
125
  c = described_class.new(princ)
117
126
  expect(c.primary_principal).to be_a(String)
@@ -125,25 +134,30 @@ RSpec.describe Kerberos::Krb5::CredentialsCache do
125
134
  c = described_class.new(princ)
126
135
  expect(c).to respond_to(:destroy)
127
136
  end
137
+
128
138
  it 'deletes credentials cache' do
129
139
  c = described_class.new(princ)
130
140
  expect { c.destroy }.not_to raise_error
131
141
  expect(cache_found?).to be false
132
142
  end
143
+
133
144
  it 'delete is an alias for destroy' do
134
145
  c = described_class.new(princ)
135
146
  expect(c).to respond_to(:delete)
136
147
  expect(c.method(:delete)).to eq(c.method(:destroy))
137
148
  end
149
+
138
150
  it 'returns false if no credentials cache' do
139
151
  c = described_class.new
140
152
  expect(c.destroy).to be false
141
153
  end
154
+
142
155
  it 'raises error when calling method on destroyed object' do
143
156
  c = described_class.new(princ)
144
157
  c.destroy
145
158
  expect { c.default_name }.to raise_error(Kerberos::Krb5::Exception)
146
159
  end
160
+
147
161
  it 'does not accept arguments' do
148
162
  c = described_class.new(princ)
149
163
  expect { c.destroy(true) }.to raise_error(ArgumentError)
data/spec/kadm5_spec.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  # spec/kadm5_spec.rb
2
2
  # RSpec tests for Kerberos::Kadm5
3
3
 
4
- require 'rkerberos'
4
+ require 'spec_helper'
5
5
  require 'socket'
6
6
 
7
- RSpec.describe Kerberos::Kadm5 do
7
+ RSpec.describe 'Kerberos::Kadm5', :kadm5 do
8
+ let(:server){ Kerberos::Kadm5::Config.new.admin_server }
9
+ subject(:klass){ Kerberos::Kadm5 }
10
+
8
11
  before(:all) do
9
- @server = Kerberos::Kadm5::Config.new.admin_server
10
12
  @host = Socket.gethostname
11
13
  @user = ENV['KRB5_ADMIN_PRINCIPAL']
12
14
  @pass = ENV['KRB5_ADMIN_PASSWORD']
@@ -23,44 +25,44 @@ RSpec.describe Kerberos::Kadm5 do
23
25
 
24
26
  describe 'constructor' do
25
27
  it 'responds to .new' do
26
- expect(described_class).to respond_to(:new)
28
+ expect(subject).to respond_to(:new)
27
29
  end
28
30
  it 'works with valid user and password' do
29
- expect { described_class.new(principal: user, password: pass) }.not_to raise_error
31
+ expect { subject.new(principal: user, password: pass) }.not_to raise_error
30
32
  end
31
33
  it 'works with valid service' do
32
34
  expect {
33
- described_class.new(principal: user, password: pass, service: 'kadmin/admin')
35
+ subject.new(principal: user, password: pass, service: 'kadmin/admin')
34
36
  }.not_to raise_error
35
37
  end
36
38
  it 'only accepts a hash argument' do
37
- expect { described_class.new(user) }.to raise_error(TypeError)
38
- expect { described_class.new(1) }.to raise_error(TypeError)
39
+ expect { subject.new(user) }.to raise_error(TypeError)
40
+ expect { subject.new(1) }.to raise_error(TypeError)
39
41
  end
40
42
  it 'accepts a block and yields itself' do
41
- expect { described_class.new(principal: user, password: pass) {} }.not_to raise_error
42
- described_class.new(principal: user, password: pass) { |kadm5| expect(kadm5).to be_a(described_class) }
43
+ expect { subject.new(principal: user, password: pass) {} }.not_to raise_error
44
+ subject.new(principal: user, password: pass) { |kadm5| expect(kadm5).to be_a(subject) }
43
45
  end
44
46
  it 'requires principal to be specified' do
45
- expect { described_class.new({}) }.to raise_error(ArgumentError)
47
+ expect { subject.new({}) }.to raise_error(ArgumentError)
46
48
  end
47
49
  it 'requires principal to be a string' do
48
- expect { described_class.new(principal: 1) }.to raise_error(TypeError)
50
+ expect { subject.new(principal: 1) }.to raise_error(TypeError)
49
51
  end
50
52
  it 'requires password to be a string' do
51
- expect { described_class.new(principal: user, password: 1) }.to raise_error(TypeError)
53
+ expect { subject.new(principal: user, password: 1) }.to raise_error(TypeError)
52
54
  end
53
55
  it 'requires keytab to be a string or boolean' do
54
- expect { described_class.new(principal: user, keytab: 1) }.to raise_error(TypeError)
56
+ expect { subject.new(principal: user, keytab: 1) }.to raise_error(TypeError)
55
57
  end
56
58
  it 'requires service to be a string' do
57
- expect { described_class.new(principal: user, password: pass, service: 1) }.to raise_error(TypeError)
59
+ expect { subject.new(principal: user, password: pass, service: 1) }.to raise_error(TypeError)
58
60
  end
59
61
  end
60
62
 
61
63
  describe '#get_privileges' do
62
64
  before(:each) do
63
- @kadm5 = described_class.new(principal: user, password: pass)
65
+ @kadm5 = subject.new(principal: user, password: pass)
64
66
  end
65
67
 
66
68
  after(:each) do
@@ -4,12 +4,13 @@
4
4
  require 'rkerberos'
5
5
  require 'tmpdir'
6
6
  require 'fileutils'
7
- require 'pty'
8
- require 'expect'
9
-
10
7
 
8
+ unless File::ALT_SEPARATOR
9
+ require 'pty'
10
+ require 'expect'
11
+ end
11
12
 
12
- RSpec.describe Kerberos::Krb5::Keytab do
13
+ RSpec.describe Kerberos::Krb5::Keytab, :kadm5 do
13
14
  before(:all) do
14
15
  @realm = Kerberos::Kadm5::Config.new.realm
15
16
  @keytab_file = File.join(Dir.tmpdir, 'test.keytab')
data/spec/krb5_spec.rb CHANGED
@@ -1,18 +1,20 @@
1
1
  # spec/krb5_spec.rb
2
2
  # RSpec tests for Kerberos::Krb5
3
3
 
4
- require 'rkerberos'
4
+ require 'spec_helper'
5
5
  require 'open3'
6
- require 'pty'
7
- require 'expect'
6
+
7
+ unless File::ALT_SEPARATOR
8
+ require 'pty'
9
+ require 'expect'
10
+ end
8
11
 
9
12
  RSpec.describe Kerberos::Krb5 do
10
13
  before(:all) do
14
+ krb5_conf = RSpec.configuration.krb5_conf
11
15
  @cache_found = true
12
16
  Open3.popen3('klist') { |_, _, stderr| @cache_found = false unless stderr.gets.nil? }
13
- @krb5_conf = ENV['KRB5_CONFIG'] || '/etc/krb5.conf'
14
- @realm = IO.read(@krb5_conf).split("\n").grep(/default_realm/).first.split('=').last.lstrip.chomp
15
-
17
+ @realm = IO.read(krb5_conf).split("\n").grep(/default_realm/).first.split('=').last.lstrip.chomp
16
18
  end
17
19
 
18
20
  subject(:krb5) { described_class.new }
@@ -21,7 +23,7 @@ RSpec.describe Kerberos::Krb5 do
21
23
  let(:service) { 'kadmin/admin' }
22
24
 
23
25
  it 'has the correct version constant' do
24
- expect(Kerberos::Krb5::VERSION).to eq('0.2.2')
26
+ expect(Kerberos::Krb5::VERSION).to eq('0.2.3')
25
27
  end
26
28
 
27
29
  it 'accepts a block and yields itself' do
@@ -48,7 +50,7 @@ RSpec.describe Kerberos::Krb5 do
48
50
  end
49
51
  end
50
52
 
51
- describe '#verify_init_creds' do
53
+ describe '#verify_init_creds', :kadm5 do
52
54
  # Some KDC setups may not correctly set the initial password during
53
55
  # entrypoint startup; enforce it here via the admin API so the test is
54
56
  # deterministic.
@@ -116,7 +118,7 @@ RSpec.describe Kerberos::Krb5 do
116
118
  end
117
119
  end
118
120
 
119
- describe '#change_password' do
121
+ describe '#change_password', :kadm5 do
120
122
  before do
121
123
  # Ensure testuser1 has a known password before each test.
122
124
  Kerberos::Kadm5.new(
@@ -186,7 +188,7 @@ RSpec.describe Kerberos::Krb5 do
186
188
  end
187
189
  end
188
190
 
189
- describe '#get_init_creds_keytab' do
191
+ describe '#get_init_creds_keytab', :unix do
190
192
  before(:each) do
191
193
  @kt_file = File.join(Dir.tmpdir, "test_get_init_creds_#{Process.pid}_#{rand(10000)}.keytab")
192
194
 
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,10 @@ 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)
22
23
  end
23
24
  end
24
25
 
@@ -28,7 +29,7 @@ RSpec.describe Kerberos::Kadm5::Policy do
28
29
  expect { policy.min_life }.not_to raise_error
29
30
  end
30
31
  it 'must be a number if not nil' do
31
- expect { described_class.new(name: 'test', min_life: 'test') }.to raise_error(TypeError)
32
+ expect { klass.new(name: 'test', min_life: 'test') }.to raise_error(TypeError)
32
33
  end
33
34
  end
34
35
 
@@ -38,7 +39,7 @@ RSpec.describe Kerberos::Kadm5::Policy do
38
39
  expect { policy.max_life }.not_to raise_error
39
40
  end
40
41
  it 'must be a number if not nil' do
41
- expect { described_class.new(name: 'test', max_life: 'test') }.to raise_error(TypeError)
42
+ expect { klass.new(name: 'test', max_life: 'test') }.to raise_error(TypeError)
42
43
  end
43
44
  end
44
45
 
@@ -12,6 +12,24 @@ RSpec.describe Kerberos::Krb5::Principal do
12
12
  expect { described_class.new(1) }.to raise_error(TypeError)
13
13
  expect { described_class.new(true) }.to raise_error(TypeError)
14
14
  end
15
+
16
+ it 'accepts an explicit nil argument' do
17
+ expect{ described_class.new(nil) }.not_to raise_error
18
+ end
19
+
20
+ it 'works as expected with a nil argument to the constructor' do
21
+ expect(described_class.new(nil).principal).to be_nil
22
+ end
23
+ end
24
+
25
+ describe '#realm' do
26
+ it 'returns the expected value' do
27
+ expect(subject.realm).to eq('EXAMPLE.COM')
28
+ end
29
+
30
+ it 'raises an error if the constructor argument was nil' do
31
+ expect{ described_class.new(nil).realm }.to raise_error(Kerberos::Krb5::Exception, /no principal/)
32
+ end
15
33
  end
16
34
 
17
35
  describe '#name' do
@@ -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.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Berger
@@ -92,6 +92,7 @@ files:
92
92
  - spec/krb5_spec.rb
93
93
  - spec/policy_spec.rb
94
94
  - spec/principal_spec.rb
95
+ - spec/spec_helper.rb
95
96
  homepage: http://github.com/rkerberos/rkerberos
96
97
  licenses:
97
98
  - Artistic-2.0