Skip to content
Browse files

Updated specs.

TODO: Check service URI even when user is logged in.
  • Loading branch information...
1 parent 76c14de commit 31d03677351c3d4cff573308d7c5b61647360763 @Slotos committed Jun 22, 2012
Showing with 119 additions and 15 deletions.
  1. +5 −1 lib/casserver/server.rb
  2. +0 −14 spec/casserver_spec.rb
  3. +54 −0 spec/strategy_config.yml
  4. +13 −0 spec/strategy_dummy.rb
  5. +47 −0 spec/strategy_spec.rb
View
6 lib/casserver/server.rb
@@ -234,7 +234,7 @@ def self.init_strategies!
begin
require ( conf[:require] || "rubycas-strategy-#{name}" )
rescue LoadError => e
- $LOG.warning "Failed require with error #{e}, attempting to load #{name} strategy anyway"
+ $LOG.debug "Failed require with error #{e}, attempting to load #{name} strategy anyway"
end
strategy = ( conf[:register] || "CASServer::Strategy::#{name.capitalize}" ).constantize
@@ -365,6 +365,8 @@ def self.init_database!
# 2.1.1
get "#{uri_path}/login" do
+ require 'pry'
+ binding.pry
CASServer::Utils::log_controller_action(self.class, params)
# make sure there's no caching
@@ -811,6 +813,8 @@ def confirm_authentication!(username, service = nil, *args)
@st = generate_service_ticket(service, username, tgt)
begin
+ require 'pry'
+ binding.pry
service_with_ticket = service_uri_with_ticket(service, @st)
$LOG.info("Redirecting authenticated user '#{username}' at '#{@st.client_hostname}' to service '#{service}'")
View
14 spec/casserver_spec.rb
@@ -153,18 +153,4 @@
page.body.should match("<test_utf_string>&#1070;&#1090;&#1092;</test_utf_string>")
end
end
-
- describe "matchers" do
- describe "oauth_links writer/accessor" do
- it "should be empty initially" do
- CASServer::Server.oauth_links.should eq("")
- end
-
- it "should provide push accessor to push string into it" do
- string = "TEST STRING PLEASE IGNORE"
- CASServer::Server.add_oauth_link string
- CASServer::Server.oauth_links.should =~ Regexp.new("#{string}$")
- end
- end
- end
end
View
54 spec/strategy_config.yml
@@ -0,0 +1,54 @@
+server: webrick
+port: 6543
+#ssl_cert: test.pem
+#uri_path: /cas
+#bind_address: 0.0.0.0
+
+# database:
+# adapter: mysql
+# database: casserver
+# username: root
+# password:
+# host: localhost
+# reconnect: true
+database:
+ adapter: sqlite3
+ database: spec/casserver_spec.db
+
+disable_auto_migrations: true
+
+quiet: true
+
+authenticator:
+ class: CASServer::Authenticators::Test
+ password: spec_password
+
+strategy:
+ dummy:
+ require: <%= "#{Dir.pwd}/spec/strategy_dummy" %>
+
+theme: simple
+
+organization: "RSPEC-TEST"
+
+infoline: "This is an rspec test."
+
+#custom_views: /path/to/custom/views
+
+default_locale: en
+
+log:
+ file: casserver_spec.log
+ level: DEBUG
+
+#db_log:
+# file: casserver_spec_db.log
+
+enable_single_sign_out: true
+
+#maximum_unused_login_ticket_lifetime: 300
+#maximum_unused_service_ticket_lifetime: 300
+
+#maximum_session_lifetime: 172800
+
+#downcase_username: true
View
13 spec/strategy_dummy.rb
@@ -0,0 +1,13 @@
+module CASServer
+ module Strategy
+ module Dummy
+ def self.registered(app)
+
+ app.get '/confirm_authentication' do
+ confirm_authentication!("someone", params[:service])
+ end
+
+ end
+ end
+ end
+end
View
47 spec/strategy_spec.rb
@@ -0,0 +1,47 @@
+# encoding: UTF-8
+require File.dirname(__FILE__) + '/spec_helper'
+include Rack::Test::Methods
+
+$LOG = Logger.new(File.basename(__FILE__).gsub('.rb','.log'))
+
+RSpec.configure do |config|
+ config.include Capybara::DSL
+end
+
+describe 'CASServer strategies' do
+ before :all do
+ app = load_server(File.dirname(__FILE__) + "/strategy_config.yml")
+ @browser = Rack::Test::Session.new( Rack::MockSession.new( app ) )
+ end
+
+ describe "oauth_links writer/accessor" do
+ it "should be empty initially" do
+ CASServer::Server.oauth_links.should eq("")
+ end
+
+ it "should provide push accessor to push string into it" do
+ string = "TEST STRING PLEASE IGNORE"
+ CASServer::Server.add_oauth_link string
+ CASServer::Server.oauth_links.should =~ Regexp.new("#{string}$")
+ end
+ end
+
+ describe "confirm_authentication" do
+ it "should set tgc" do
+ @browser.get '/confirm_authentication'
+ @browser.instance_variable_get(:@rack_mock_session).cookie_jar["tgt"].should =~ /^TGC-[0-9rA-Z]+$/
+ end
+
+ it "should redirect to service if service is given" do
+ service = "http://somewhere.else/"
+ visit "/confirm_authentication?service=#{service}"
+ page.current_url.should =~ Regexp.new("^#{service}\\?ticket=ST-[0-9rA-Z]+$")
+ end
+
+ it "should not redirect to service if service is not a valid URI" do
+ service = "Hey, I'm not an URI, seriously!"
+ @browser.get "/confirm_authentication?service=#{service}"
+ @browser.last_response.should_not be_redirect
+ end
+ end
+end

0 comments on commit 31d0367

Please sign in to comment.
Something went wrong with that request. Please try again.