kensa 1.2.0rc7 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/sso_test.rb CHANGED
@@ -1,70 +1,130 @@
1
- $:.unshift(File.expand_path("../..",__FILE__))
2
- require 'test/lib/dependencies'
1
+ require 'test/helper'
2
+ require 'cgi'
3
+
3
4
  class SsoTest < Test::Unit::TestCase
5
+ include Heroku::Kensa
4
6
 
5
- def setup
6
- super
7
- @user_id ||= manifest["user_id"] || 123
8
- @time = Time.now.to_i
9
- @params = { :timestamp => @time,
10
- :token => make_token(@user_id, manifest['api']["sso_salt"], @time.to_s),
11
- "nav-data" => "some-nav-data"
12
- }
13
- end
7
+ context "with GET" do
8
+ setup do
9
+ @data = Manifest.new.skeleton.merge(:id => 1)
10
+ @data['api']['test'] = 'http://localhost:4567/'
11
+ @data['api']['sso_salt'] = 'SSO_SALT'
12
+ end
14
13
 
15
- def sso_post?
16
- manifest["api"]["test"].is_a?(Hash) &&
17
- manifest["api"]["test"]["sso_url"]
18
- end
14
+ teardown { Timecop.return }
19
15
 
20
- def sso_url
21
- if sso_post?
22
- manifest["api"]["test"]["sso_url"].chomp("/")
23
- else
24
- "/heroku/resources"
16
+ def builds_full_url(env)
17
+ url, query = @sso.full_url.split('?')
18
+ data = CGI.parse(query)
19
+
20
+
21
+ assert_equal "#{@data['api'][env]}heroku/resources/1", url
22
+ assert_equal 'b6010f6fbb850887a396c2bc0ab23974003008f6', data['token'].first
23
+ assert_equal '1262304000', data['timestamp'].first
24
+ assert_equal 'username@example.com', data['email'].first
25
25
  end
26
- end
27
26
 
28
- def sso_login(params = @params, user_id = @user_id)
29
- if sso_post?
30
- post sso_url, params.merge(:id => user_id)
31
- else
32
- get "#{sso_url}/#{user_id}", params
27
+ context 'sso' do
28
+ setup do
29
+ Timecop.freeze Time.utc(2010, 1)
30
+ @sso = Sso.new @data
31
+ end
32
+
33
+ test 'builds path' do
34
+ assert_equal '/heroku/resources/1', @sso.path
35
+ end
36
+
37
+ test 'builds full url' do
38
+ builds_full_url('test')
39
+ end
40
+
41
+ context 'with no "sso" field specified' do
42
+ test "defaults to GET" do
43
+ assert_equal @sso.full_url, @sso.sso_url
44
+ end
45
+ end
46
+
47
+ context 'when sso method is GET' do
48
+ setup do
49
+ @data['api']['sso'] = 'GET'
50
+ @sso = Sso.new(@data).start
51
+ end
52
+
53
+ test "#sso_url should be the #full_url" do
54
+ assert_equal @sso.full_url, @sso.sso_url
55
+ end
56
+
57
+ test "#message is Opening <full_url>" do
58
+ assert_equal "Opening #{@sso.full_url}", @sso.message
59
+ end
60
+ end
61
+
33
62
  end
34
- end
35
63
 
36
- def test_validates_token
37
- @params[:token] = "foo"
38
- response = sso_login
39
- assert_equal 403, response.code, "Signing in via SSO at /heroku/resources/:id must return a 403 if the token is invalid."
40
- end
64
+ context 'sso without salt' do
65
+ setup do
66
+ @data['api'].delete 'sso_salt'
67
+ @sso = Sso.new @data
68
+ end
41
69
 
42
- def test_validates_timestamp
43
- @params[:timestamp] = (Time.now-60*3).to_i
44
- @params[:token] = make_token(123, "SSO_SALT", @params[:timestamp].to_s)
45
- response = sso_login
46
- assert_equal 403, response.code, "Signing in via SSO at /heroku/resources/:id must return a 403 if the timestamp is expired."
70
+ test 'builds full url' do
71
+ expected = 'http://localhost:4567/heroku/resources/1'
47
72
 
48
- @params[:timestamp] = "foo"
49
- response = sso_login
50
- assert_equal 403, response.code, "Signing in via SSO at /heroku/resources/:id must return a 403 if the timestamp is invalid."
51
- end
73
+ assert @sso.full_url.include?(expected)
74
+ end
75
+ end
52
76
 
53
- def test_logs_in
54
- response = sso_login
55
- assert response.code.to_s.match(/\A2/), "Signing in via SSO at /heroku/resources/:id must return a 2xx response if sign in was valid."
56
- end
77
+ context 'sso in production' do
78
+ setup do
79
+ Timecop.freeze Time.utc(2010, 1)
80
+ env = 'production'
81
+ @data[:env] = env
82
+ @data['api'][env] = 'http://localhost:7654/'
57
83
 
58
- def test_creates_the_heroku_nav_data_cookie
59
- response = sso_login
84
+ @sso = Sso.new @data
85
+ end
60
86
 
61
- assert response.cookies, "SSO sign in should set the heroku-nav-data cookie to the value of the passed nav-data parameter."
62
- assert_equal @params["nav-data"], response.cookies["heroku-nav-data"], "SSO sign in should set the heroku-nav-data cookie to the value of the passed nav-data parameter."
87
+ test 'builds full url' do
88
+ builds_full_url('production')
89
+ end
90
+ end
63
91
  end
64
92
 
65
- def test_displays_the_heroku_layout
66
- response = sso_login
67
- document = Nokogiri::HTML.parse(response.body)
68
- assert !document.search("div#heroku-header").empty?, "Logged in page should contain the Heroku header."
93
+ context "via POST" do
94
+ setup do
95
+ Timecop.freeze Time.utc(2010, 1)
96
+ @data = Manifest.new(:method => :post).skeleton.merge(:id => 1)
97
+ @data['api']['sso_salt'] = 'SSO_SALT'
98
+ end
99
+
100
+ test "it starts the proxy server" do
101
+ @sso = Sso.new(@data).start
102
+ body = RestClient.get(@sso.sso_url)
103
+
104
+ assert body.include? @sso.path
105
+ assert body.include? 'b6010f6fbb850887a396c2bc0ab23974003008f6'
106
+ assert body.include? '1262304000'
107
+ assert body.include? @sso.url
108
+ assert body.include? @sso.sample_nav_data
109
+ end
110
+
111
+ context "with the proxy working" do
112
+ setup do
113
+ any_instance_of(Sso, :run_proxy => false)
114
+ @sso = Sso.new(@data).start
115
+ end
116
+
117
+ test "#sso_url should point to the proxy" do
118
+ assert_equal "http://localhost:#{@sso.proxy_port}/", @sso.sso_url
119
+ end
120
+
121
+ test "#post_url contains url and path" do
122
+ assert_equal "http://localhost:4567/sso/login", @sso.post_url
123
+ end
124
+
125
+ test "#message is Posting <data> to <post_url> via proxy on port <proxy_port>" do
126
+ assert_equal "POSTing #{@sso.query_data} to http://localhost:4567/sso/login via proxy on port #{@sso.proxy_port}", @sso.message
127
+ end
128
+ end
69
129
  end
70
130
  end
metadata CHANGED
@@ -1,23 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kensa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0rc7
5
- prerelease: 5
4
+ version: 1.2.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Blake Mizerany
9
9
  - Pedro Belo
10
10
  - Adam Wiggins
11
- - Chris Continanza
12
11
  - Glenn Gillen
12
+ - Chris Continanza
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2011-10-25 00:00:00.000000000Z
16
+ date: 2011-11-18 00:00:00.000000000Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
- name: json
20
- requirement: &70357298670540 !ruby/object:Gem::Requirement
19
+ name: contest
20
+ requirement: &70130076419400 !ruby/object:Gem::Requirement
21
21
  none: false
22
22
  requirements:
23
23
  - - ! '>='
@@ -25,120 +25,134 @@ dependencies:
25
25
  version: '0'
26
26
  type: :development
27
27
  prerelease: false
28
- version_requirements: *70357298670540
28
+ version_requirements: *70130076419400
29
29
  - !ruby/object:Gem::Dependency
30
- name: sinatra
31
- requirement: &70357298669740 !ruby/object:Gem::Requirement
30
+ name: timecop
31
+ requirement: &70130076416540 !ruby/object:Gem::Requirement
32
32
  none: false
33
33
  requirements:
34
- - - ~>
34
+ - - ! '>='
35
35
  - !ruby/object:Gem::Version
36
- version: 1.2.6
36
+ version: 0.3.5
37
37
  type: :development
38
38
  prerelease: false
39
- version_requirements: *70357298669740
39
+ version_requirements: *70130076416540
40
40
  - !ruby/object:Gem::Dependency
41
- name: timecop
42
- requirement: &70357298668860 !ruby/object:Gem::Requirement
41
+ name: sinatra
42
+ requirement: &70130076414660 !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
45
- - - ~>
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.5
47
+ version: '0.9'
48
48
  type: :development
49
49
  prerelease: false
50
- version_requirements: *70357298668860
50
+ version_requirements: *70130076414660
51
51
  - !ruby/object:Gem::Dependency
52
- name: rr
53
- requirement: &70357298668060 !ruby/object:Gem::Requirement
52
+ name: json
53
+ requirement: &70130076412640 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
- - - ~>
56
+ - - ! '>='
57
57
  - !ruby/object:Gem::Version
58
- version: 1.0.4
58
+ version: '0'
59
59
  type: :development
60
60
  prerelease: false
61
- version_requirements: *70357298668060
61
+ version_requirements: *70130076412640
62
62
  - !ruby/object:Gem::Dependency
63
- name: artifice
64
- requirement: &70357298667400 !ruby/object:Gem::Requirement
63
+ name: contest
64
+ requirement: &70130076411500 !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ~>
67
+ - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: '0.6'
69
+ version: '0'
70
70
  type: :development
71
71
  prerelease: false
72
- version_requirements: *70357298667400
72
+ version_requirements: *70130076411500
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: haml
75
- requirement: &70357298665960 !ruby/object:Gem::Requirement
75
+ requirement: &70130076410000 !ruby/object:Gem::Requirement
76
76
  none: false
77
77
  requirements:
78
- - - ~>
78
+ - - ! '>='
79
79
  - !ruby/object:Gem::Version
80
- version: 3.1.3
80
+ version: '0'
81
81
  type: :development
82
82
  prerelease: false
83
- version_requirements: *70357298665960
83
+ version_requirements: *70130076410000
84
84
  - !ruby/object:Gem::Dependency
85
- name: test-unit
86
- requirement: &70357298665280 !ruby/object:Gem::Requirement
85
+ name: rr
86
+ requirement: &70130076408820 !ruby/object:Gem::Requirement
87
87
  none: false
88
88
  requirements:
89
- - - ~>
89
+ - - ! '>='
90
90
  - !ruby/object:Gem::Version
91
- version: 1.2.3
92
- type: :runtime
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: *70130076408820
95
+ - !ruby/object:Gem::Dependency
96
+ name: fakefs
97
+ requirement: &70130076407080 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
93
104
  prerelease: false
94
- version_requirements: *70357298665280
105
+ version_requirements: *70130076407080
95
106
  - !ruby/object:Gem::Dependency
96
107
  name: rest-client
97
- requirement: &70357298664240 !ruby/object:Gem::Requirement
108
+ requirement: &70130076404080 !ruby/object:Gem::Requirement
98
109
  none: false
99
110
  requirements:
100
- - - ~>
111
+ - - <
112
+ - !ruby/object:Gem::Version
113
+ version: 1.7.0
114
+ - - ! '>='
101
115
  - !ruby/object:Gem::Version
102
- version: 1.6.7
116
+ version: 1.4.0
103
117
  type: :runtime
104
118
  prerelease: false
105
- version_requirements: *70357298664240
119
+ version_requirements: *70130076404080
106
120
  - !ruby/object:Gem::Dependency
107
121
  name: yajl-ruby
108
- requirement: &70357298662400 !ruby/object:Gem::Requirement
122
+ requirement: &70130076399200 !ruby/object:Gem::Requirement
109
123
  none: false
110
124
  requirements:
111
125
  - - ~>
112
126
  - !ruby/object:Gem::Version
113
- version: 0.8.3
127
+ version: '0.6'
114
128
  type: :runtime
115
129
  prerelease: false
116
- version_requirements: *70357298662400
130
+ version_requirements: *70130076399200
117
131
  - !ruby/object:Gem::Dependency
118
132
  name: term-ansicolor
119
- requirement: &70357298661220 !ruby/object:Gem::Requirement
133
+ requirement: &70130076396960 !ruby/object:Gem::Requirement
120
134
  none: false
121
135
  requirements:
122
136
  - - ~>
123
137
  - !ruby/object:Gem::Version
124
- version: 1.0.6
138
+ version: '1.0'
125
139
  type: :runtime
126
140
  prerelease: false
127
- version_requirements: *70357298661220
141
+ version_requirements: *70130076396960
128
142
  - !ruby/object:Gem::Dependency
129
143
  name: launchy
130
- requirement: &70357298659880 !ruby/object:Gem::Requirement
144
+ requirement: &70130076393800 !ruby/object:Gem::Requirement
131
145
  none: false
132
146
  requirements:
133
- - - ~>
147
+ - - ! '>='
134
148
  - !ruby/object:Gem::Version
135
- version: 2.0.5
149
+ version: 0.3.2
136
150
  type: :runtime
137
151
  prerelease: false
138
- version_requirements: *70357298659880
152
+ version_requirements: *70130076393800
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: mechanize
141
- requirement: &70357298658860 !ruby/object:Gem::Requirement
155
+ requirement: &70130076392720 !ruby/object:Gem::Requirement
142
156
  none: false
143
157
  requirements:
144
158
  - - ~>
@@ -146,22 +160,11 @@ dependencies:
146
160
  version: 1.0.0
147
161
  type: :runtime
148
162
  prerelease: false
149
- version_requirements: *70357298658860
150
- - !ruby/object:Gem::Dependency
151
- name: artifice
152
- requirement: &70357298657560 !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ~>
156
- - !ruby/object:Gem::Version
157
- version: 0.6.0
158
- type: :runtime
159
- prerelease: false
160
- version_requirements: *70357298657560
163
+ version_requirements: *70130076392720
161
164
  description: Kensa is a command-line tool to help add-on providers integrating their
162
165
  services with Heroku. It manages manifest files, and provides a TDD-like approach
163
166
  for programmers to test and develop their APIs.
164
- email: glenn@heroku.com
167
+ email: pedro@heroku.com
165
168
  executables:
166
169
  - kensa
167
170
  extensions: []
@@ -175,28 +178,29 @@ files:
175
178
  - bin/kensa
176
179
  - kensa.gemspec
177
180
  - lib/heroku/kensa.rb
181
+ - lib/heroku/kensa/check.rb
178
182
  - lib/heroku/kensa/client.rb
183
+ - lib/heroku/kensa/git.rb
179
184
  - lib/heroku/kensa/http.rb
180
185
  - lib/heroku/kensa/manifest.rb
181
186
  - lib/heroku/kensa/post_proxy.rb
187
+ - lib/heroku/kensa/screen.rb
182
188
  - lib/heroku/kensa/sso.rb
183
189
  - lib/heroku/kensa/version.rb
184
190
  - set-env.sh
185
- - test.rb
191
+ - test/all_check_test.rb
186
192
  - test/create_test.rb
187
- - test/deprovision_test.rb
193
+ - test/deprovision_check_test.rb
188
194
  - test/helper.rb
189
- - test/lib/dependencies.rb
190
- - test/lib/formatter.rb
191
- - test/lib/http.rb
192
- - test/lib/response.rb
193
- - test/manifest_generation_test.rb
195
+ - test/init_test.rb
196
+ - test/manifest_check_test.rb
194
197
  - test/manifest_test.rb
195
- - test/plan_change_test.rb
196
- - test/provision_test.rb
197
- - test/resources/provider_server.rb
198
- - test/resources/views/index.haml
199
- - test/sso_launch_test.rb
198
+ - test/plan_change_check_test.rb
199
+ - test/provision_check_test.rb
200
+ - test/provision_response_check_test.rb
201
+ - test/resources/runner.rb
202
+ - test/resources/server.rb
203
+ - test/sso_check_test.rb
200
204
  - test/sso_test.rb
201
205
  homepage: http://provider.heroku.com/resources
202
206
  licenses: []
@@ -212,13 +216,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
216
  version: '0'
213
217
  segments:
214
218
  - 0
215
- hash: 2597895003724042539
219
+ hash: 3834118791582110421
216
220
  required_rubygems_version: !ruby/object:Gem::Requirement
217
221
  none: false
218
222
  requirements:
219
- - - ! '>'
223
+ - - ! '>='
220
224
  - !ruby/object:Gem::Version
221
- version: 1.3.1
225
+ version: '0'
226
+ segments:
227
+ - 0
228
+ hash: 3834118791582110421
222
229
  requirements: []
223
230
  rubyforge_project: kensa
224
231
  rubygems_version: 1.8.10
@@ -226,18 +233,17 @@ signing_key:
226
233
  specification_version: 3
227
234
  summary: Tool to help Heroku add-on providers integrating their services
228
235
  test_files:
236
+ - test/all_check_test.rb
229
237
  - test/create_test.rb
230
- - test/deprovision_test.rb
238
+ - test/deprovision_check_test.rb
231
239
  - test/helper.rb
232
- - test/lib/dependencies.rb
233
- - test/lib/formatter.rb
234
- - test/lib/http.rb
235
- - test/lib/response.rb
236
- - test/manifest_generation_test.rb
240
+ - test/init_test.rb
241
+ - test/manifest_check_test.rb
237
242
  - test/manifest_test.rb
238
- - test/plan_change_test.rb
239
- - test/provision_test.rb
240
- - test/resources/provider_server.rb
241
- - test/resources/views/index.haml
242
- - test/sso_launch_test.rb
243
+ - test/plan_change_check_test.rb
244
+ - test/provision_check_test.rb
245
+ - test/provision_response_check_test.rb
246
+ - test/resources/runner.rb
247
+ - test/resources/server.rb
248
+ - test/sso_check_test.rb
243
249
  - test/sso_test.rb