Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/rubycas-server-core/tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Core
module Tickets

# One time login ticket for given client
def generate_login_ticket(client)
def self.generate_login_ticket(client)
lt = LoginTicket.new
lt.ticket = "LT-" + Util.random_string
lt.client_hostname = client
Expand All @@ -24,7 +24,7 @@ def generate_login_ticket(client)
# The optional 'extra_attributes' parameter takes a hash of additional attributes
# that will be sent along with the username in the CAS response to subsequent
# validation requests from clients.
def generate_ticket_granting_ticket(username, client, extra_attributes = {})
def self.generate_ticket_granting_ticket(username, client, extra_attributes = {})
tgt = TicketGrantingTicket.new
tgt.ticket = "TGC-" + Util.random_string
tgt.username = username
Expand All @@ -40,7 +40,7 @@ def generate_ticket_granting_ticket(username, client, extra_attributes = {})
end
end

def generate_service_ticket(service, username, tgt, client)
def self.generate_service_ticket(service, username, tgt, client)
st = ServiceTicket.new
st.ticket = "ST-" + Util.random_string
st.service = service
Expand All @@ -56,14 +56,13 @@ def generate_service_ticket(service, username, tgt, client)
end
end

def generate_proxy_ticket(target_service, pgt, client)
def self.generate_proxy_ticket(target_service, pgt, client)
raise NotImplementedError
end

def generate_proxy_granting_ticket(pgt_url, st, client)
def self.generate_proxy_granting_ticket(pgt_url, st, client)
raise NotImplementedError
end

end
end
end
Expand Down
9 changes: 5 additions & 4 deletions spec/rubycas-server-core/tickets/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
}
@cas = klass.new
@client_hostname = "myhost.test"
Tickets = RubyCAS::Server::Core::Tickets
end

describe "validate login ticket" do
it "should validate login ticket" do
@lt = @cas.generate_login_ticket(@client_hostname)
@lt = Tickets.generate_login_ticket(@client_hostname)
success, error = @cas.validate_login_ticket(@lt.ticket)
success.should be_true
error.should be_nil
Expand All @@ -24,7 +25,7 @@
before do
@username = 'myuser'
@client_hostname = "myhost.test"
@tgt = @cas.generate_ticket_granting_ticket(@username, @client_hostname)
@tgt = Tickets.generate_ticket_granting_ticket(@username, @client_hostname)
end

it "should validate ticket granting ticket" do
Expand All @@ -39,8 +40,8 @@
@username = 'testuser'
@client_hostname = "myhost.test"
@service = 'myservice.test'
@tgt = @cas.generate_ticket_granting_ticket(@username, @client_hostname)
@st = @cas.generate_service_ticket(@service, @username, @tgt, @client_hostname)
@tgt = Tickets.generate_ticket_granting_ticket(@username, @client_hostname)
@st = Tickets.generate_service_ticket(@service, @username, @tgt, @client_hostname)
end

it "should validate service ticket" do
Expand Down
159 changes: 74 additions & 85 deletions spec/rubycas-server-core/tickets_spec.rb
Original file line number Diff line number Diff line change
@@ -1,116 +1,105 @@
require "spec_helper"

describe RubyCAS::Server::Core::Tickets do
before do
RubyCAS::Server::Core.setup("spec/config/config.yml")
klass = Class.new {
include RubyCAS::Server::Core::Tickets
}
@cas = klass.new
@client_hostname = "myhost.test"
end

Tickets = RubyCAS::Server::Core::Tickets
module RubyCAS::Server::Core
describe RubyCAS::Server::Core::Tickets do
let(:client_hostname) { 'myhost.test' }
let(:username) { 'myuser' }
let(:service) { 'https://myservice.test' }

describe "login ticket object" do
before do
@lt = @cas.generate_login_ticket(@client_hostname)
RubyCAS::Server::Core.setup("spec/config/config.yml")
klass = Class.new {
include RubyCAS::Server::Core::Tickets
}
@cas = klass.new
@client_hostname = "myhost.test"
end

it "should return a login ticket" do
@lt.class.should == Tickets::LoginTicket
end
describe '.generate_login_ticket(client_hostname)' do
let(:lt) { Tickets.generate_login_ticket(client_hostname) }

it "should set the client_hostname" do
@lt.client_hostname.should == @client_hostname
end
it "should return a login ticket" do
lt.class.should == Tickets::LoginTicket
end

it "should set the ticket string" do
@lt.ticket.should_not be_nil
end
it "should set the client_hostname" do
lt.client_hostname.should == client_hostname
end

it "should set the ticket string starting with 'LT'" do
@lt.ticket.should match /^LT/
end
it "should set the ticket string" do
lt.ticket.should_not be_nil
end

it "should not mark the ticket as consumed" do
@lt.consumed.should be_nil
end
end
it "should set the ticket string starting with 'LT'" do
lt.ticket.should match /^LT/
end

describe "#generate_ticket_granting_ticket(username, extra_attributes = {})" do
before do
@username = 'myuser'
@client_hostname = "myhost.test"
@tgt = @cas.generate_ticket_granting_ticket(@username, @client_hostname)
it "should not mark the ticket as consumed" do
lt.consumed.should be_nil
end
end

it "should return a TicketGrantingTicket" do
@tgt.class.should == Tickets::TicketGrantingTicket
end
describe ".generate_ticket_granting_ticket(username, extra_attributes = {})" do
let(:tgt) { Tickets.generate_ticket_granting_ticket(username, client_hostname) }

it "should set the tgt's ticket string" do
@tgt.ticket.should_not be_nil
end
it "should return a TicketGrantingTicket" do
tgt.class.should == Tickets::TicketGrantingTicket
end

it "should generate a ticket string starting with 'TGC'" do
@tgt.ticket.should match /^TGC/
end
it "should set the tgt's ticket string" do
tgt.ticket.should_not be_nil
end

it "should set the tgt's username string" do
@tgt.username.should == @username
end
it "should generate a ticket string starting with 'TGC'" do
tgt.ticket.should match /^TGC/
end

it "should set the tgt's client_hostname" do
@tgt.client_hostname.should == @client_hostname
end
it "should set the tgt's username string" do
tgt.username.should == username
end

end

describe "#generate_service_ticket(service, username, tgt)" do
before do
@username = 'testuser'
@client_hostname = "myhost.test"
@service = 'myservice.test'
@tgt = @cas.generate_ticket_granting_ticket(@username, @client_hostname)
@st = @cas.generate_service_ticket(@service, @username, @tgt, @client_hostname)
it "should set the tgt's client_hostname" do
tgt.client_hostname.should == client_hostname
end
end

it "should return a ServiceTicket" do
@st.class.should == Tickets::ServiceTicket
end
describe ".generate_service_ticket(service, username, tgt)" do
let(:tgt) { Tickets.generate_ticket_granting_ticket(username, client_hostname) }
let(:st) { Tickets.generate_service_ticket(service, username, tgt, client_hostname) }

it "should not include the service identifer in the ticket string" do
@st.ticket.should_not match /#{@service}/
end
it "should return a ServiceTicket" do
st.class.should == Tickets::ServiceTicket
end

it "should not mark the ST as consumed" do
@st.consumed.should be_nil
end
it "should not include the service identifer in the ticket string" do
st.ticket.should_not match /#{service}/
end

it "must generate a ticket that starts with 'ST-'" do
@st.ticket.should match /^ST-/
end
it "should not mark the ST as consumed" do
st.consumed.should be_nil
end

it "should assoicate the ST with the supplied TGT" do
@st.ticket_granting_ticket.id.should == @tgt.id
end

end

describe "#generate_proxy_ticket(target_service, pgt)" do
it "must generate a ticket that starts with 'ST-'" do
st.ticket.should match /^ST-/
end

it "should return a ProxyGrantingTicket" do
pending("Proxy ticket is not implemented yet")
it "should assoicate the ST with the supplied TGT" do
st.ticket_granting_ticket.id.should == tgt.id
end
end

it "should not consume the generated ticket" do
pending("Proxy ticket is not implemented yet")
end
describe ".generate_proxy_ticket(target_service, pgt)" do
it "should return a ProxyGrantingTicket" do
pending("Proxy ticket is not implemented yet")
end

it "should not consume the generated ticket" do
pending("Proxy ticket is not implemented yet")
end

it "should start the ticket string with PT-" do
pending("Proxy ticket is not implemented yet")
it "should start the ticket string with PT-" do
pending("Proxy ticket is not implemented yet")
end
end
end

end