This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
/
sso_test.rb
145 lines (115 loc) · 3.7 KB
/
sso_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
require 'test/helper'
require 'cgi'
class SsoTest < Test::Unit::TestCase
include Heroku::Kensa
context "with GET" do
setup do
@data = Manifest.new.skeleton.merge(:id => 1)
@data['api']['test'] = 'http://localhost:4567/'
@data['api']['sso_salt'] = 'SSO_SALT'
end
teardown { Timecop.return }
def builds_full_url(env)
url, query = @sso.full_url.split('?')
data = CGI.parse(query)
assert_equal "#{@data['api'][env]}heroku/resources/1", url
assert_equal 'b6010f6fbb850887a396c2bc0ab23974003008f6', data['token'].first
assert_equal '1262304000', data['timestamp'].first
assert_equal 'username@example.com', data['email'].first
end
context 'sso' do
setup do
Timecop.freeze Time.utc(2010, 1)
@sso = Sso.new @data
end
test 'builds path' do
assert_equal '/heroku/resources/1', @sso.path
end
test 'builds full url' do
builds_full_url('test')
end
context 'with no "sso" field specified' do
test "defaults to GET" do
assert_equal @sso.full_url, @sso.sso_url
end
end
context 'when sso method is GET' do
setup do
@data['api']['sso'] = 'GET'
@sso = Sso.new(@data).start
end
test "#sso_url should be the #full_url" do
assert_equal @sso.full_url, @sso.sso_url
end
test "#message is Opening <full_url>" do
assert_equal "Opening #{@sso.full_url}", @sso.message
end
end
end
context 'sso without salt' do
setup do
@data['api'].delete 'sso_salt'
@sso = Sso.new @data
end
test 'builds full url' do
expected = 'http://localhost:4567/heroku/resources/1'
assert @sso.full_url.include?(expected)
end
end
context 'sso in production' do
setup do
Timecop.freeze Time.utc(2010, 1)
env = 'production'
@data[:env] = env
@data['api'][env] = 'http://localhost:7654/'
@sso = Sso.new @data
end
test 'builds full url' do
builds_full_url('production')
end
end
end
context "via POST" do
include FsMock
setup do
Timecop.freeze Time.utc(2010, 1)
@data = Manifest.new(:method => :post).skeleton
@data['api']['sso_salt'] = 'SSO_SALT'
end
test "command line" do
any_instance_of(Client) { |c| stub(c).puts }
stub(Launchy).open
start = Object.new
stub(start).message
stub(start).sso_url
stub(Sso).new.stub!.start.returns(start)
kensa "init"
kensa "sso 1234"
assert_received(Sso) { |sso| sso.new(hash_including(:id => '1234')) }
end
test "it starts the proxy server" do
@sso = Sso.new(@data.merge(:id => 1)).start
body = RestClient.get(@sso.sso_url)
assert body.include? @sso.path
assert body.include? 'b6010f6fbb850887a396c2bc0ab23974003008f6'
assert body.include? '1262304000'
assert body.include? @sso.url
assert body.include? @sso.sample_nav_data
end
context "with the proxy working" do
setup do
any_instance_of(Sso, :run_proxy => false)
@sso = Sso.new(@data).start
end
test "#sso_url should point to the proxy" do
assert_equal "http://localhost:#{@sso.proxy_port}/", @sso.sso_url
end
test "#post_url contains url and path" do
assert_equal "http://localhost:4567/sso/login", @sso.post_url
end
test "#message is Posting <data> to <post_url> via proxy on port <proxy_port>" do
assert_equal "POSTing #{@sso.query_data} to http://localhost:4567/sso/login via proxy on port #{@sso.proxy_port}", @sso.message
end
end
end
end