casino_core 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.5
1
+ 1.0.6
data/casino_core.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "casino_core"
8
- s.version = "1.0.5"
8
+ s.version = "1.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nils Caspar"]
12
- s.date = "2012-12-30"
12
+ s.date = "2012-12-31"
13
13
  s.description = "A CAS server core library."
14
14
  s.email = "ncaspar@me.com"
15
15
  s.extra_rdoc_files = [
@@ -16,8 +16,9 @@ class CASinoCore::Processor::API::LoginCredentialAcceptor < CASinoCore::Processo
16
16
  # * `#invalid_login_credentials_via_api`: No argument
17
17
  #
18
18
  # @param [Hash] login_data parameters supplied by user (username and password)
19
- def process(login_data)
19
+ def process(login_data, user_agent = nil)
20
20
  @login_data = login_data
21
+ @user_agent = user_agent
21
22
 
22
23
  validate_login_data
23
24
 
@@ -39,7 +40,7 @@ class CASinoCore::Processor::API::LoginCredentialAcceptor < CASinoCore::Processo
39
40
  end
40
41
 
41
42
  def generate_ticket_granting_ticket
42
- @ticket_granting_ticket = acquire_ticket_granting_ticket(@authentication_result)
43
+ @ticket_granting_ticket = acquire_ticket_granting_ticket(@authentication_result, @user_agent)
43
44
  end
44
45
 
45
46
  def callback_invalid_login_credentials
@@ -2,16 +2,15 @@ require 'casino_core/processor'
2
2
  require 'casino_core/helper'
3
3
  require 'casino_core/model'
4
4
 
5
- # The Logout processor should be used to process API DELET requests to /cas/v1/tickets/TGT-fdsjfsdfjkalfewrihfdhfaie
5
+ # The Logout processor should be used to process API DELETE requests to /cas/v1/tickets/<ticket_granting_ticket>
6
6
  class CASinoCore::Processor::API::Logout < CASinoCore::Processor
7
7
  include CASinoCore::Helper::TicketGrantingTickets
8
8
 
9
- # This method will call `#user_logged_out_via_api`
9
+ # This method will call `#user_logged_out_via_api` on the listener.
10
10
  #
11
- # @param [String] ticket_granting_ticket Ticket granting ticket to logout
12
- def process(ticket_granting_ticket)
13
-
14
- remove_ticket_granting_ticket(ticket_granting_ticket)
11
+ # @param [String] ticket_granting_ticket Ticket-granting ticket to logout
12
+ def process(ticket_granting_ticket, user_agent = nil)
13
+ remove_ticket_granting_ticket(ticket_granting_ticket, user_agent)
15
14
  callback_user_logged_out
16
15
  end
17
16
 
@@ -11,15 +11,19 @@ class CASinoCore::Processor::API::ServiceTicketProvider < CASinoCore::Processor
11
11
  # Use this method to process the request.
12
12
  #
13
13
  # The method will call one of the following methods on the listener:
14
- # * `#granted_service_ticket_via_api`: First and only argument is a String with the ST-id
15
- # * `#invalid_ticket_granting_ticket_via_api`: No argument
16
- # * `#no_service_provided_via_api`: No argument
14
+ # * `#granted_service_ticket_via_api`: First and only argument is a String with the service ticket.
15
+ # The service ticket (and nothing else) should be displayed.
16
+ # * `#invalid_ticket_granting_ticket_via_api`: No argument. The application should respond with status "400 Bad Request"
17
+ # * `#no_service_provided_via_api`: No argument. The application should respond with status "400 Bad Request"
17
18
  #
18
19
  # @param [String] ticket_granting_ticket ticket_granting_ticket supplied by the user in the URL
19
- # @param [Hash] parameters parameters supplied by user (ticket granting ticket and service url)
20
- def process(ticket_granting_ticket, parameters)
20
+ # @param [Hash] parameters parameters supplied by user (`service` in particular)
21
+ # @param [String] user_agent user-agent delivered by the client
22
+ def process(ticket_granting_ticket, parameters = nil, user_agent = nil)
23
+ parameters ||= {}
21
24
  @client_ticket_granting_ticket = ticket_granting_ticket
22
25
  @service_url = parameters[:service]
26
+ @user_agent = user_agent
23
27
 
24
28
  fetch_valid_ticket_granting_ticket
25
29
  handle_ticket_granting_ticket
@@ -27,7 +31,7 @@ class CASinoCore::Processor::API::ServiceTicketProvider < CASinoCore::Processor
27
31
 
28
32
  private
29
33
  def fetch_valid_ticket_granting_ticket
30
- @ticket_granting_ticket = find_valid_ticket_granting_ticket(@client_ticket_granting_ticket, nil)
34
+ @ticket_granting_ticket = find_valid_ticket_granting_ticket(@client_ticket_granting_ticket, @user_agent)
31
35
  end
32
36
 
33
37
  def handle_ticket_granting_ticket
@@ -4,34 +4,49 @@ describe CASinoCore::Processor::API::LoginCredentialAcceptor do
4
4
  describe '#process' do
5
5
  let(:listener) { Object.new }
6
6
  let(:processor) { described_class.new(listener) }
7
+ let(:user_agent) { 'ThisIsATestBrwoser 1.0' }
7
8
 
8
9
  context 'with invalid credentials' do
9
- let(:login_data) { {username: 'testuser', password: 'wrong'} }
10
+ let(:login_data) { { username: 'testuser', password: 'wrong' } }
10
11
 
11
- it 'calls the #invalid_login_credentials method on the listener' do
12
+ before(:each) do
13
+ listener.stub(:invalid_login_credentials_via_api)
14
+ end
15
+
16
+ it 'calls the #invalid_login_credentials_via_api method on the listener' do
12
17
  listener.should_receive(:invalid_login_credentials_via_api)
13
- processor.process(login_data).should be_false
18
+ processor.process(login_data, user_agent).should be_false
19
+ end
20
+
21
+ it 'does not generate a ticket-granting ticket' do
22
+ expect {
23
+ processor.process(login_data, user_agent)
24
+ }.to_not change(CASinoCore::Model::TicketGrantingTicket, :count)
14
25
  end
15
26
  end
16
27
 
17
28
  context 'with valid credentials' do
18
- let(:login_data) { {username: 'testuser', password: 'foobar123'} }
29
+ let(:login_data) { { username: 'testuser', password: 'foobar123' } }
19
30
 
20
31
  before(:each) do
21
- listener.stub(:user_logged_in)
32
+ listener.stub(:user_logged_in_via_api)
22
33
  end
23
34
 
24
- it 'calls the #user_logged_in method on the listener' do
35
+ it 'calls the #user_logged_in_via_api method on the listener' do
25
36
  listener.should_receive(:user_logged_in_via_api).with(/^TGC\-/)
26
- processor.process(login_data)
37
+ processor.process(login_data, user_agent)
27
38
  end
28
39
 
29
40
  it 'generates a ticket-granting ticket' do
30
- listener.should_receive(:user_logged_in_via_api).with(/^TGC\-/)
31
41
  expect {
32
- processor.process(login_data)
42
+ processor.process(login_data, user_agent)
33
43
  }.to change(CASinoCore::Model::TicketGrantingTicket, :count).by(1)
34
44
  end
45
+
46
+ it 'sets the user-agent in the ticket-granting ticket' do
47
+ processor.process(login_data, user_agent)
48
+ CASinoCore::Model::TicketGrantingTicket.last.user_agent.should == user_agent
49
+ end
35
50
  end
36
51
  end
37
52
  end
@@ -6,22 +6,23 @@ describe CASinoCore::Processor::API::Logout do
6
6
  let(:processor) { described_class.new(listener) }
7
7
 
8
8
  context 'with an existing ticket-granting ticket' do
9
- let(:ticket_granting_ticket) { FactoryGirl.create(:ticket_granting_ticket, user_agent: nil) }
9
+ let(:ticket_granting_ticket) { FactoryGirl.create(:ticket_granting_ticket) }
10
+ let(:user_agent) { ticket_granting_ticket.user_agent }
10
11
 
11
12
  it 'deletes the ticket-granting ticket' do
12
13
  listener.should_receive(:user_logged_out_via_api)
13
- processor.process(ticket_granting_ticket.ticket)
14
+ processor.process(ticket_granting_ticket.ticket, user_agent)
14
15
  CASinoCore::Model::TicketGrantingTicket.where(id: ticket_granting_ticket.id).first.should == nil
15
16
  end
16
17
 
17
18
  it 'calls the #user_logged_out_via_api method on the listener' do
18
19
  listener.should_receive(:user_logged_out_via_api)
19
- processor.process(ticket_granting_ticket)
20
+ processor.process(ticket_granting_ticket, user_agent)
20
21
  end
21
22
 
22
23
  end
23
24
 
24
- context 'with an invlaid ticket-granting ticket' do
25
+ context 'with an invalid ticket-granting ticket' do
25
26
  let(:tgt) { 'TGT-lalala' }
26
27
 
27
28
  it 'calls the #user_logged_out method on the listener' do
@@ -17,17 +17,19 @@ describe CASinoCore::Processor::API::ServiceTicketProvider do
17
17
  end
18
18
 
19
19
  context 'with a valid ticket-granting ticket' do
20
- let(:ticket_granting_ticket) { FactoryGirl.create(:ticket_granting_ticket, user_agent: nil).ticket }
20
+ let(:ticket_granting_ticket) { FactoryGirl.create(:ticket_granting_ticket) }
21
+ let(:ticket) { ticket_granting_ticket.ticket }
22
+ let(:user_agent) { ticket_granting_ticket.user_agent }
21
23
 
22
24
  it 'calls the #granted_service_ticket_via_api method on the listener' do
23
25
  listener.should_receive(:granted_service_ticket_via_api).with(/^ST\-/)
24
- processor.process(ticket_granting_ticket, parameters)
26
+ processor.process(ticket, parameters, user_agent)
25
27
  end
26
28
 
27
29
  it 'generates a ticket-granting ticket' do
28
30
  listener.should_receive(:granted_service_ticket_via_api).with(/^ST\-/)
29
31
  expect {
30
- processor.process(ticket_granting_ticket, parameters)
32
+ processor.process(ticket, parameters, user_agent)
31
33
  }.to change(CASinoCore::Model::ServiceTicket, :count).by(1)
32
34
  end
33
35
 
@@ -36,7 +38,7 @@ describe CASinoCore::Processor::API::ServiceTicketProvider do
36
38
 
37
39
  it 'calls the #no_service_provided_via_api method on the listener' do
38
40
  listener.should_receive(:no_service_provided_via_api)
39
- processor.process(ticket_granting_ticket, parameters)
41
+ processor.process(ticket, parameters, user_agent)
40
42
  end
41
43
  end
42
44
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: casino_core
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.5
5
+ version: 1.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nils Caspar
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-12-30 00:00:00 Z
13
+ date: 2012-12-31 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -288,7 +288,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
288
288
  requirements:
289
289
  - - ">="
290
290
  - !ruby/object:Gem::Version
291
- hash: -2705901659147789141
291
+ hash: -3280265477686707578
292
292
  segments:
293
293
  - 0
294
294
  version: "0"