|
1 | 1 | require "spec_helper" |
2 | 2 |
|
3 | | -describe RubyCAS::Server::Core::Tickets do |
4 | | - before do |
5 | | - RubyCAS::Server::Core.setup("spec/config/config.yml") |
6 | | - klass = Class.new { |
7 | | - include RubyCAS::Server::Core::Tickets |
8 | | - } |
9 | | - @cas = klass.new |
10 | | - @client_hostname = "myhost.test" |
11 | | - end |
12 | | - |
13 | | - Tickets = RubyCAS::Server::Core::Tickets |
| 3 | +module RubyCAS::Server::Core |
| 4 | + describe RubyCAS::Server::Core::Tickets do |
| 5 | + let(:client_hostname) { 'myhost.test' } |
| 6 | + let(:username) { 'myuser' } |
| 7 | + let(:service) { 'https://myservice.test' } |
14 | 8 |
|
15 | | - describe "login ticket object" do |
16 | 9 | before do |
17 | | - @lt = @cas.generate_login_ticket(@client_hostname) |
| 10 | + RubyCAS::Server::Core.setup("spec/config/config.yml") |
| 11 | + klass = Class.new { |
| 12 | + include RubyCAS::Server::Core::Tickets |
| 13 | + } |
| 14 | + @cas = klass.new |
| 15 | + @client_hostname = "myhost.test" |
18 | 16 | end |
19 | 17 |
|
20 | | - it "should return a login ticket" do |
21 | | - @lt.class.should == Tickets::LoginTicket |
22 | | - end |
| 18 | + describe '.generate_login_ticket(client_hostname)' do |
| 19 | + let(:lt) { Tickets.generate_login_ticket(client_hostname) } |
23 | 20 |
|
24 | | - it "should set the client_hostname" do |
25 | | - @lt.client_hostname.should == @client_hostname |
26 | | - end |
| 21 | + it "should return a login ticket" do |
| 22 | + lt.class.should == Tickets::LoginTicket |
| 23 | + end |
27 | 24 |
|
28 | | - it "should set the ticket string" do |
29 | | - @lt.ticket.should_not be_nil |
30 | | - end |
| 25 | + it "should set the client_hostname" do |
| 26 | + lt.client_hostname.should == client_hostname |
| 27 | + end |
31 | 28 |
|
32 | | - it "should set the ticket string starting with 'LT'" do |
33 | | - @lt.ticket.should match /^LT/ |
34 | | - end |
| 29 | + it "should set the ticket string" do |
| 30 | + lt.ticket.should_not be_nil |
| 31 | + end |
35 | 32 |
|
36 | | - it "should not mark the ticket as consumed" do |
37 | | - @lt.consumed.should be_nil |
38 | | - end |
39 | | - end |
| 33 | + it "should set the ticket string starting with 'LT'" do |
| 34 | + lt.ticket.should match /^LT/ |
| 35 | + end |
40 | 36 |
|
41 | | - describe "#generate_ticket_granting_ticket(username, extra_attributes = {})" do |
42 | | - before do |
43 | | - @username = 'myuser' |
44 | | - @client_hostname = "myhost.test" |
45 | | - @tgt = @cas.generate_ticket_granting_ticket(@username, @client_hostname) |
| 37 | + it "should not mark the ticket as consumed" do |
| 38 | + lt.consumed.should be_nil |
| 39 | + end |
46 | 40 | end |
47 | 41 |
|
48 | | - it "should return a TicketGrantingTicket" do |
49 | | - @tgt.class.should == Tickets::TicketGrantingTicket |
50 | | - end |
| 42 | + describe ".generate_ticket_granting_ticket(username, extra_attributes = {})" do |
| 43 | + let(:tgt) { Tickets.generate_ticket_granting_ticket(username, client_hostname) } |
51 | 44 |
|
52 | | - it "should set the tgt's ticket string" do |
53 | | - @tgt.ticket.should_not be_nil |
54 | | - end |
| 45 | + it "should return a TicketGrantingTicket" do |
| 46 | + tgt.class.should == Tickets::TicketGrantingTicket |
| 47 | + end |
55 | 48 |
|
56 | | - it "should generate a ticket string starting with 'TGC'" do |
57 | | - @tgt.ticket.should match /^TGC/ |
58 | | - end |
| 49 | + it "should set the tgt's ticket string" do |
| 50 | + tgt.ticket.should_not be_nil |
| 51 | + end |
59 | 52 |
|
60 | | - it "should set the tgt's username string" do |
61 | | - @tgt.username.should == @username |
62 | | - end |
| 53 | + it "should generate a ticket string starting with 'TGC'" do |
| 54 | + tgt.ticket.should match /^TGC/ |
| 55 | + end |
63 | 56 |
|
64 | | - it "should set the tgt's client_hostname" do |
65 | | - @tgt.client_hostname.should == @client_hostname |
66 | | - end |
| 57 | + it "should set the tgt's username string" do |
| 58 | + tgt.username.should == username |
| 59 | + end |
67 | 60 |
|
68 | | - end |
69 | | - |
70 | | - describe "#generate_service_ticket(service, username, tgt)" do |
71 | | - before do |
72 | | - @username = 'testuser' |
73 | | - @client_hostname = "myhost.test" |
74 | | - @service = 'myservice.test' |
75 | | - @tgt = @cas.generate_ticket_granting_ticket(@username, @client_hostname) |
76 | | - @st = @cas.generate_service_ticket(@service, @username, @tgt, @client_hostname) |
| 61 | + it "should set the tgt's client_hostname" do |
| 62 | + tgt.client_hostname.should == client_hostname |
| 63 | + end |
77 | 64 | end |
78 | 65 |
|
79 | | - it "should return a ServiceTicket" do |
80 | | - @st.class.should == Tickets::ServiceTicket |
81 | | - end |
| 66 | + describe ".generate_service_ticket(service, username, tgt)" do |
| 67 | + let(:tgt) { Tickets.generate_ticket_granting_ticket(username, client_hostname) } |
| 68 | + let(:st) { Tickets.generate_service_ticket(service, username, tgt, client_hostname) } |
82 | 69 |
|
83 | | - it "should not include the service identifer in the ticket string" do |
84 | | - @st.ticket.should_not match /#{@service}/ |
85 | | - end |
| 70 | + it "should return a ServiceTicket" do |
| 71 | + st.class.should == Tickets::ServiceTicket |
| 72 | + end |
86 | 73 |
|
87 | | - it "should not mark the ST as consumed" do |
88 | | - @st.consumed.should be_nil |
89 | | - end |
| 74 | + it "should not include the service identifer in the ticket string" do |
| 75 | + st.ticket.should_not match /#{service}/ |
| 76 | + end |
90 | 77 |
|
91 | | - it "must generate a ticket that starts with 'ST-'" do |
92 | | - @st.ticket.should match /^ST-/ |
93 | | - end |
| 78 | + it "should not mark the ST as consumed" do |
| 79 | + st.consumed.should be_nil |
| 80 | + end |
94 | 81 |
|
95 | | - it "should assoicate the ST with the supplied TGT" do |
96 | | - @st.ticket_granting_ticket.id.should == @tgt.id |
97 | | - end |
98 | | - |
99 | | - end |
100 | | - |
101 | | - describe "#generate_proxy_ticket(target_service, pgt)" do |
| 82 | + it "must generate a ticket that starts with 'ST-'" do |
| 83 | + st.ticket.should match /^ST-/ |
| 84 | + end |
102 | 85 |
|
103 | | - it "should return a ProxyGrantingTicket" do |
104 | | - pending("Proxy ticket is not implemented yet") |
| 86 | + it "should assoicate the ST with the supplied TGT" do |
| 87 | + st.ticket_granting_ticket.id.should == tgt.id |
| 88 | + end |
105 | 89 | end |
106 | 90 |
|
107 | | - it "should not consume the generated ticket" do |
108 | | - pending("Proxy ticket is not implemented yet") |
109 | | - end |
| 91 | + describe ".generate_proxy_ticket(target_service, pgt)" do |
| 92 | + it "should return a ProxyGrantingTicket" do |
| 93 | + pending("Proxy ticket is not implemented yet") |
| 94 | + end |
| 95 | + |
| 96 | + it "should not consume the generated ticket" do |
| 97 | + pending("Proxy ticket is not implemented yet") |
| 98 | + end |
110 | 99 |
|
111 | | - it "should start the ticket string with PT-" do |
112 | | - pending("Proxy ticket is not implemented yet") |
| 100 | + it "should start the ticket string with PT-" do |
| 101 | + pending("Proxy ticket is not implemented yet") |
| 102 | + end |
113 | 103 | end |
114 | 104 | end |
115 | | - |
116 | 105 | end |
0 commit comments