File: gssapi_simple_spec.rb

package info (click to toggle)
ruby-gssapi 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208 kB
  • sloc: ruby: 820; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 2,017 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$: << File.dirname(__FILE__) + '/../../lib/'
require 'gssapi'
require 'base64'
require 'yaml'


describe GSSAPI::Simple, 'Test the Simple GSSAPI interface' do

  let(:conf) { YAML.load_file "#{File.dirname(__FILE__)}/conf_file.yaml" }
  let(:cli) { GSSAPI::Simple.new(conf['s_host'], conf['s_service']) }
  let(:srv ) { GSSAPI::Simple.new(conf['s_host'], conf['s_service'], conf['keytab']) }

  it 'should get the initial context for a client' do
    token = cli.init_context
    expect(token).not_to be_empty
  end

  it 'should acquire credentials for a server service' do
    expect(srv.acquire_credentials).to eq(true)
  end

  def play_handshake(cli,srv,clioptions={})
    clitoken = cli.init_context(nil, clioptions)
    expect(clitoken).not_to be_empty

    expect(srv.acquire_credentials).to eq(true)

    srvoktok = srv.accept_context(clitoken)
    expect(srvoktok).not_to be_empty

    ret = cli.init_context(srvoktok)
    expect(ret).to eq(true)
  end

  it 'client server should handshake' do
    play_handshake(cli,srv)
  end

  it 'mic' do
    play_handshake(cli,srv)

    secret = "this is secreta"

    mic = cli.get_mic(secret)

    expect(srv.verify_mic(secret,mic)).to eq(true)
  end

  context "no delegation" do
    it "sets delegated_credentials to nil" do
      play_handshake(cli,srv,:delegate => false)
      expect(srv.delegated_credentials).to be_nil
    end
  end

  describe "delegation" do
    it "sets delegated_credentials to valid" do
      play_handshake(cli,srv,:delegate => true)
      expect(srv.delegated_credentials).not_to be_nil
      delegated_display_name = srv.display_name

      host2 = conf['s_host2'] || conf['s_host']
      service2 = conf['s_service2'] || conf['s_service']
      cli_del = GSSAPI::Simple.new(host2, service2)
      srv_del = GSSAPI::Simple.new(host2, service2, conf['keytab2'])
      play_handshake(cli_del,srv_del,:credentials => srv.delegated_credentials)
      expect(srv_del.display_name).to eq(delegated_display_name)
    end
  end
end if false