File: client_spec.rb

package info (click to toggle)
ruby-ntlm 0.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 408 kB
  • sloc: ruby: 2,663; makefile: 6
file content (64 lines) | stat: -rw-r--r-- 2,616 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
require 'spec_helper'

describe Net::NTLM::Client do
  let(:inst) { Net::NTLM::Client.new("test", "test01", :workstation => "testhost") }
  let(:user_session_key) {["3c4918ff0b33e2603e5d7ceaf34bb7d5"].pack("H*")}

  describe "#init_context" do

    it "returns a default Type1 message" do
      t1 = inst.init_context
      expect(t1).to be_instance_of Net::NTLM::Message::Type1
      expect(t1.domain).to eq("")
      expect(t1.workstation).to eq("testhost")
      expect(t1).to have_flag(:UNICODE)
      expect(t1).to have_flag(:OEM)
      expect(t1).to have_flag(:SIGN)
      expect(t1).to have_flag(:SEAL)
      expect(t1).to have_flag(:REQUEST_TARGET)
      expect(t1).to have_flag(:NTLM)
      expect(t1).to have_flag(:ALWAYS_SIGN)
      expect(t1).to have_flag(:NTLM2_KEY)
      expect(t1).to have_flag(:KEY128)
      expect(t1).to have_flag(:KEY_EXCHANGE)
      expect(t1).to have_flag(:KEY56)
    end

    it "clears session variable on new init_context" do
      inst.instance_variable_set :@session, "BADSESSION"
      expect(inst.session).to eq("BADSESSION")
      inst.init_context
      expect(inst.session).to be_nil
    end

    it "returns a Type1 message with custom flags" do
      flags = Net::NTLM::FLAGS[:UNICODE] | Net::NTLM::FLAGS[:REQUEST_TARGET] | Net::NTLM::FLAGS[:NTLM]
      inst = Net::NTLM::Client.new("test", "test01", :workstation => "testhost", :flags => flags)
      t1 = inst.init_context
      expect(t1).to be_instance_of Net::NTLM::Message::Type1
      expect(t1.domain).to eq("")
      expect(t1.workstation).to eq("testhost")
      expect(t1).to have_flag(:UNICODE)
      expect(t1).not_to have_flag(:OEM)
      expect(t1).not_to have_flag(:SIGN)
      expect(t1).not_to have_flag(:SEAL)
      expect(t1).to have_flag(:REQUEST_TARGET)
      expect(t1).to have_flag(:NTLM)
      expect(t1).not_to have_flag(:ALWAYS_SIGN)
      expect(t1).not_to have_flag(:NTLM2_KEY)
      expect(t1).not_to have_flag(:KEY128)
      expect(t1).not_to have_flag(:KEY_EXCHANGE)
      expect(t1).not_to have_flag(:KEY56)
    end

    it "calls authenticate! when we receive a Challenge Message" do
      t2_challenge = "TlRMTVNTUAACAAAADAAMADgAAAA1goriAAyk1DmJUnUAAAAAAAAAAFAAUABEAAAABgLwIwAAAA9TAEUAUgBWAEUAUgACAAwAUwBFAFIAVgBFAFIAAQAMAFMARQBSAFYARQBSAAQADABzAGUAcgB2AGUAcgADAAwAcwBlAHIAdgBlAHIABwAIADd7mrNaB9ABAAAAAA=="
      session = double("session")
      expect(session).to receive(:authenticate!)
      expect(Net::NTLM::Client::Session).to receive(:new).with(inst, instance_of(Net::NTLM::Message::Type2), nil).and_return(session)
      inst.init_context t2_challenge
    end

  end

end