rubycas-server 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,150 @@
1
+ require 'rubygems'
2
+ require 'mosquito'
3
+
4
+ $CONF = {:authenticator => {:class => "CASServer::Authenticators::Test"}}
5
+
6
+ require File.dirname(__FILE__) + "/../lib/casserver"
7
+
8
+ include CASServer::Models
9
+ CASServer.create
10
+
11
+ class TestCASServer < Camping::FunctionalTest
12
+
13
+ def test_test_atuhenticator
14
+ require File.dirname(__FILE__) + "/../lib/casserver/authenticators/test"
15
+
16
+ valid_credentials = {:username => "testuser", :password => "testpassword"}
17
+ invalid_credentials = {:username => "asdfsdf", :password => "asdfsdf"}
18
+
19
+ assert_equal CASServer::Authenticators::Test, $AUTH.class
20
+ assert $AUTH.validate(valid_credentials)
21
+ assert !$AUTH.validate(invalid_credentials)
22
+ end
23
+
24
+ def test_valid_login
25
+ lt = start_login
26
+
27
+ post '/login',
28
+ :lt => lt.ticket,
29
+ :username => "testuser",
30
+ :password => "testpassword"
31
+
32
+ assert_match_body("You have successfully logged in")
33
+
34
+ lt = LoginTicket.find_by_ticket(lt.ticket)
35
+
36
+ assert_not_nil @cookies[:tgt]
37
+ assert_not_nil TicketGrantingTicket.find_by_ticket(@cookies[:tgt])
38
+
39
+ assert lt.consumed?
40
+ end
41
+
42
+ def test_valid_login_with_service
43
+ lt = start_login
44
+
45
+ fake_service = "http://www.google.com/"
46
+
47
+ post '/login',
48
+ :lt => lt.ticket,
49
+ :username => "testuser",
50
+ :password => "testpassword",
51
+ :service => fake_service
52
+
53
+ @response.headers['Location'].to_s =~ /(.*?)\?ticket=(.*)/
54
+ redirected_to = $~[1]
55
+ service_ticket = $~[2]
56
+
57
+ assert_equal fake_service, redirected_to
58
+
59
+ assert_not_nil service_ticket
60
+ st = ServiceTicket.find_by_ticket(service_ticket)
61
+ assert_equal fake_service, st.service
62
+ assert_equal "testuser", st.username
63
+ assert !st.consumed?
64
+
65
+ assert_not_nil @cookies[:tgt]
66
+ assert_not_nil TicketGrantingTicket.find_by_ticket(@cookies[:tgt])
67
+
68
+ assert LoginTicket.find_by_ticket(lt.ticket).consumed?
69
+ end
70
+
71
+ def test_invalid_login
72
+ lt = start_login
73
+
74
+ post '/login',
75
+ :lt => lt.ticket,
76
+ :username => "testuser",
77
+ :password => "badpassword"
78
+
79
+ assert_match_body("Incorrect username or password")
80
+
81
+ # reusing the same login ticket should fail
82
+ post '/login',
83
+ :lt => lt.ticket,
84
+ :username => "testuser",
85
+ :password => "testpassword"
86
+
87
+ assert_match_body("The login ticket you provided has already been used up")
88
+
89
+ # missing username/password
90
+ lt = start_login
91
+ post '/login',
92
+ :lt => lt.ticket
93
+
94
+ assert_match_body("Incorrect username or password")
95
+
96
+ # missing login ticket
97
+ post '/login',
98
+ :username => "testuser",
99
+ :password => "testpassword"
100
+
101
+ assert_match_body("Your login request did not include a login ticket")
102
+ end
103
+
104
+ private
105
+ def start_login
106
+ assert_difference(LoginTicket, :count, 1) do
107
+ get '/login'
108
+ end
109
+
110
+ assert_response :success
111
+ assert_match_body("Login")
112
+
113
+ @response.body =~ /LT-[a-zA-Z0-9]*/
114
+ lt = $~[0]
115
+ assert_not_nil lt
116
+
117
+ lt = LoginTicket.find_by_ticket(lt)
118
+ assert_not_nil lt
119
+
120
+ assert !lt.consumed?
121
+
122
+ lt
123
+ end
124
+
125
+ end
126
+
127
+ #class TestPost < Camping::UnitTest
128
+ #
129
+ # fixtures :blog_posts, :blog_users, :blog_comments
130
+ #
131
+ # def test_create
132
+ # post = create
133
+ # assert post.valid?
134
+ # end
135
+ #
136
+ # def test_assoc
137
+ # post = Post.find :first
138
+ # assert_kind_of User, post.user
139
+ # assert_equal 1, post.user.id
140
+ # end
141
+ #
142
+ # private
143
+ #
144
+ # def create(options={})
145
+ # Post.create({ :user_id => 1,
146
+ # :title => "Title",
147
+ # :body => "Body"}.merge(options))
148
+ # end
149
+ #
150
+ #end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: rubycas-server
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-03-08 00:00:00 -05:00
8
+ summary: Provides single sign on for web applications using the CAS protocol.
9
+ require_paths:
10
+ - lib
11
+ email: matt@roughest.net
12
+ homepage: http://rubycas-server.rubyforge.org
13
+ rubyforge_project: rubycas-server
14
+ description: Provides single sign on for web applications using the CAS protocol.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Matt Zukowski
31
+ files:
32
+ - CHANGELOG.txt
33
+ - LICENSE.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ - Rakefile
37
+ - config.example.yml
38
+ - lib/casserver.rb
39
+ - lib/casserver/authenticators/active_directory_ldap.rb
40
+ - lib/casserver/authenticators/base.rb
41
+ - lib/casserver/authenticators/ldap.rb
42
+ - lib/casserver/authenticators/sql.rb
43
+ - lib/casserver/authenticators/test.rb
44
+ - lib/casserver/cas.rb
45
+ - lib/casserver/conf.rb
46
+ - lib/casserver/controllers.rb
47
+ - lib/casserver/models.rb
48
+ - lib/casserver/utils.rb
49
+ - lib/casserver/version.rb
50
+ - lib/casserver/views.rb
51
+ - lib/themes/cas.css
52
+ - lib/themes/ok.png
53
+ - lib/themes/simple/bg.png
54
+ - lib/themes/simple/login_box_bg.png
55
+ - lib/themes/simple/logo.png
56
+ - lib/themes/simple/theme.css
57
+ - lib/themes/urbacon/bg.png
58
+ - lib/themes/urbacon/login_box_bg.png
59
+ - lib/themes/urbacon/logo.png
60
+ - lib/themes/urbacon/theme.css
61
+ - lib/themes/warning.png
62
+ - setup.rb
63
+ - test/test_casserver.rb
64
+ test_files:
65
+ - test/test_casserver.rb
66
+ rdoc_options: []
67
+
68
+ extra_rdoc_files: []
69
+
70
+ executables:
71
+ - rubycas-server
72
+ extensions: []
73
+
74
+ requirements: []
75
+
76
+ dependencies:
77
+ - !ruby/object:Gem::Dependency
78
+ name: camping
79
+ version_requirement:
80
+ version_requirements: !ruby/object:Gem::Version::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "1.5"
85
+ version:
86
+ - !ruby/object:Gem::Dependency
87
+ name: sqlite3-ruby
88
+ version_requirement:
89
+ version_requirements: !ruby/object:Gem::Version::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 1.2.0
94
+ version:
95
+ - !ruby/object:Gem::Dependency
96
+ name: activesupport
97
+ version_requirement:
98
+ version_requirements: !ruby/object:Gem::Version::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.4.0
103
+ version: