Skip to content

Commit 5ad8b5d

Browse files
author
Robert Mitwicki
committed
Merge pull request #14 from rubycas/ticket-spec
Ticket improvements
2 parents 81db0fd + 25a38de commit 5ad8b5d

3 files changed

Lines changed: 84 additions & 95 deletions

File tree

lib/rubycas-server-core/tickets.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Core
66
module Tickets
77

88
# One time login ticket for given client
9-
def generate_login_ticket(client)
9+
def self.generate_login_ticket(client)
1010
lt = LoginTicket.new
1111
lt.ticket = "LT-" + Util.random_string
1212
lt.client_hostname = client
@@ -24,7 +24,7 @@ def generate_login_ticket(client)
2424
# The optional 'extra_attributes' parameter takes a hash of additional attributes
2525
# that will be sent along with the username in the CAS response to subsequent
2626
# validation requests from clients.
27-
def generate_ticket_granting_ticket(username, client, extra_attributes = {})
27+
def self.generate_ticket_granting_ticket(username, client, extra_attributes = {})
2828
tgt = TicketGrantingTicket.new
2929
tgt.ticket = "TGC-" + Util.random_string
3030
tgt.username = username
@@ -40,7 +40,7 @@ def generate_ticket_granting_ticket(username, client, extra_attributes = {})
4040
end
4141
end
4242

43-
def generate_service_ticket(service, username, tgt, client)
43+
def self.generate_service_ticket(service, username, tgt, client)
4444
st = ServiceTicket.new
4545
st.ticket = "ST-" + Util.random_string
4646
st.service = service
@@ -56,14 +56,13 @@ def generate_service_ticket(service, username, tgt, client)
5656
end
5757
end
5858

59-
def generate_proxy_ticket(target_service, pgt, client)
59+
def self.generate_proxy_ticket(target_service, pgt, client)
6060
raise NotImplementedError
6161
end
6262

63-
def generate_proxy_granting_ticket(pgt_url, st, client)
63+
def self.generate_proxy_granting_ticket(pgt_url, st, client)
6464
raise NotImplementedError
6565
end
66-
6766
end
6867
end
6968
end

spec/rubycas-server-core/tickets/validations_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
}
1010
@cas = klass.new
1111
@client_hostname = "myhost.test"
12+
Tickets = RubyCAS::Server::Core::Tickets
1213
end
1314

1415
describe "validate login ticket" do
1516
it "should validate login ticket" do
16-
@lt = @cas.generate_login_ticket(@client_hostname)
17+
@lt = Tickets.generate_login_ticket(@client_hostname)
1718
success, error = @cas.validate_login_ticket(@lt.ticket)
1819
success.should be_true
1920
error.should be_nil
@@ -24,7 +25,7 @@
2425
before do
2526
@username = 'myuser'
2627
@client_hostname = "myhost.test"
27-
@tgt = @cas.generate_ticket_granting_ticket(@username, @client_hostname)
28+
@tgt = Tickets.generate_ticket_granting_ticket(@username, @client_hostname)
2829
end
2930

3031
it "should validate ticket granting ticket" do
@@ -39,8 +40,8 @@
3940
@username = 'testuser'
4041
@client_hostname = "myhost.test"
4142
@service = 'myservice.test'
42-
@tgt = @cas.generate_ticket_granting_ticket(@username, @client_hostname)
43-
@st = @cas.generate_service_ticket(@service, @username, @tgt, @client_hostname)
43+
@tgt = Tickets.generate_ticket_granting_ticket(@username, @client_hostname)
44+
@st = Tickets.generate_service_ticket(@service, @username, @tgt, @client_hostname)
4445
end
4546

4647
it "should validate service ticket" do
Lines changed: 74 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,105 @@
11
require "spec_helper"
22

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' }
148

15-
describe "login ticket object" do
169
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"
1816
end
1917

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) }
2320

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
2724

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
3128

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
3532

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
4036

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
4640
end
4741

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) }
5144

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
5548

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
5952

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
6356

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
6760

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
7764
end
7865

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) }
8269

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
8673

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
9077

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
9481

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
10285

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
10589
end
10690

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
11099

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
113103
end
114104
end
115-
116105
end

0 commit comments

Comments
 (0)