kensa 0.4.2 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,13 @@
1
- require File.dirname(__FILE__) + "/helper"
1
+ require 'test/helper'
2
2
 
3
3
  class ProvisionResponseCheckTest < Test::Unit::TestCase
4
- include Heroku::Sensei
4
+ include Heroku::Kensa
5
5
 
6
6
  def check ; ProvisionResponseCheck ; end
7
7
 
8
8
  setup do
9
9
  @response = { "id" => "123" }
10
- @data = Manifest.skeleton.merge(:provision_response => @response)
10
+ @data = Manifest.new.skeleton.merge(:provision_response => @response)
11
11
  @data['api']['config_vars'] << "MYADDON_CONFIG"
12
12
  end
13
13
 
@@ -0,0 +1 @@
1
+ exit(1) if ARGV.first == 'fail'
@@ -25,8 +25,10 @@ helpers do
25
25
  Digest::SHA1.hexdigest([params[:id], 'SSO_SALT', params[:timestamp]].join(':'))
26
26
  end
27
27
 
28
- def login
28
+ def login(heroku_user=true)
29
+ session.clear
29
30
  session[:logged_in] = true
31
+ session[:heroku] = heroku_user
30
32
  redirect '/'
31
33
  end
32
34
  end
@@ -62,26 +64,68 @@ post '/invalid-missing-auth/heroku/resources' do
62
64
  end
63
65
 
64
66
 
67
+ delete '/working/heroku/resources/:id' do
68
+ heroku_only!
69
+ "Ok"
70
+ end
71
+
72
+
65
73
  get '/working/heroku/resources/:id' do
66
74
  unauthorized! unless params[:id] && params[:token]
67
75
  unauthorized! unless params[:timestamp].to_i > (Time.now-60*2).to_i
68
76
  unauthorized! unless params[:token] == make_token
77
+ response.set_cookie('heroku-nav-data', params['nav-data'])
69
78
  login
70
79
  end
71
80
 
72
81
  get '/notoken/heroku/resources/:id' do
73
82
  unauthorized! unless params[:id] && params[:token]
74
83
  unauthorized! unless params[:timestamp].to_i > (Time.now-60*2).to_i
84
+ response.set_cookie('heroku-nav-data', params['nav-data'])
75
85
  login
76
86
  end
77
87
 
78
88
  get '/notimestamp/heroku/resources/:id' do
79
89
  unauthorized! unless params[:id] && params[:token]
80
90
  unauthorized! unless params[:token] == make_token
91
+ response.set_cookie('heroku-nav-data', params['nav-data'])
92
+ login
93
+ end
94
+
95
+ get '/nolayout/heroku/resources/:id' do
96
+ unauthorized! unless params[:id] && params[:token]
97
+ unauthorized! unless params[:timestamp].to_i > (Time.now-60*2).to_i
98
+ unauthorized! unless params[:token] == make_token
99
+ response.set_cookie('heroku-nav-data', params['nav-data'])
100
+ login(false)
101
+ end
102
+
103
+ get '/nocookie/heroku/resources/:id' do
104
+ unauthorized! unless params[:id] && params[:token]
105
+ unauthorized! unless params[:timestamp].to_i > (Time.now-60*2).to_i
106
+ unauthorized! unless params[:token] == make_token
107
+ login
108
+ end
109
+
110
+ get '/badcookie/heroku/resources/:id' do
111
+ unauthorized! unless params[:id] && params[:token]
112
+ unauthorized! unless params[:timestamp].to_i > (Time.now-60*2).to_i
113
+ unauthorized! unless params[:token] == make_token
114
+ response.set_cookie('heroku-nav-data', 'wrong value')
81
115
  login
82
116
  end
83
117
 
84
118
  get '/' do
85
119
  unauthorized! unless session[:logged_in]
86
- "OK"
87
- end
120
+ haml :index
121
+ end
122
+
123
+ __END__
124
+
125
+ @@ index
126
+ %html
127
+ %body
128
+ - if session[:heroku]
129
+ #heroku-header
130
+ %h1 Heroku
131
+ %h1 Sample Addon
@@ -1,10 +1,10 @@
1
- require File.dirname(__FILE__) + "/helper"
1
+ require 'test/helper'
2
2
 
3
3
  class SsoCheckTest < Test::Unit::TestCase
4
- include Heroku::Sensei
4
+ include Heroku::Kensa
5
5
 
6
6
  setup do
7
- @data = Manifest.skeleton.merge :id => 123
7
+ @data = Manifest.new.skeleton.merge :id => 123
8
8
  @data['api']['sso_salt'] = 'SSO_SALT'
9
9
  end
10
10
 
@@ -25,4 +25,25 @@ class SsoCheckTest < Test::Unit::TestCase
25
25
  assert_invalid
26
26
  end
27
27
 
28
+ test "reject omitted sso salt" do
29
+ @data['api'].delete 'sso_salt'
30
+ @data['api']['test'] += "working"
31
+ assert_invalid
32
+ end
33
+
34
+ test "reject missing heroku layout" do
35
+ @data['api']['test'] += "nolayout"
36
+ assert_invalid
37
+ end
38
+
39
+ test "reject missing cookie" do
40
+ @data['api']['test'] += "nocookie"
41
+ assert_invalid
42
+ end
43
+
44
+ test "reject invalid cookie value" do
45
+ @data['api']['test'] += "badcookie"
46
+ assert_invalid
47
+ end
48
+
28
49
  end
data/test/sso_test.rb ADDED
@@ -0,0 +1,58 @@
1
+ require 'test/helper'
2
+
3
+ class SsoTest < Test::Unit::TestCase
4
+ include Heroku::Kensa
5
+
6
+ setup do
7
+ @data = Manifest.new.skeleton.merge(:id => 1)
8
+ @data['api']['test'] = 'http://localhost:4567/'
9
+ @data['api']['sso_salt'] = 'SSO_SALT'
10
+ end
11
+
12
+ teardown { Timecop.return }
13
+
14
+ context 'sso' do
15
+ setup { @sso = Sso.new @data }
16
+
17
+ test 'builds path' do
18
+ assert_equal '/heroku/resources/1', @sso.path
19
+ end
20
+
21
+ test 'builds full url' do
22
+ Timecop.freeze Time.utc(2010, 1)
23
+ expected = 'http://localhost:4567/heroku/resources/1?token=b6010f6fbb850887a396c2bc0ab23974003008f6&timestamp=1262304000'
24
+
25
+ assert @sso.full_url.include?(expected)
26
+ end
27
+ end
28
+
29
+ context 'sso without salt' do
30
+ setup do
31
+ @data['api'].delete 'sso_salt'
32
+ @sso = Sso.new @data
33
+ end
34
+
35
+ test 'builds full url' do
36
+ expected = 'http://localhost:4567/heroku/resources/1'
37
+
38
+ assert @sso.full_url.include?(expected)
39
+ end
40
+ end
41
+
42
+ context 'sso in a specific environment' do
43
+ setup do
44
+ env = 'production'
45
+ @data[:env] = env
46
+ @data['api'][env] = 'http://localhost:7654/'
47
+
48
+ @sso = Sso.new @data
49
+ end
50
+
51
+ test 'builds full url' do
52
+ Timecop.freeze Time.utc(2010, 1)
53
+ expected = 'http://localhost:7654/heroku/resources/1?token=b6010f6fbb850887a396c2bc0ab23974003008f6&timestamp=1262304000'
54
+
55
+ assert @sso.full_url.include?(expected)
56
+ end
57
+ end
58
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kensa
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
+ - 1
7
+ - 0
6
8
  - 0
7
- - 4
8
- - 2
9
- version: 0.4.2
9
+ - beta1
10
+ version: 1.0.0.beta1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Blake Mizerany
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-05-21 00:00:00 -07:00
20
+ date: 2010-07-19 00:00:00 -07:00
20
21
  default_executable: kensa
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -44,9 +45,23 @@ dependencies:
44
45
  type: :development
45
46
  version_requirements: *id002
46
47
  - !ruby/object:Gem::Dependency
47
- name: sinatra
48
+ name: timecop
48
49
  prerelease: false
49
50
  requirement: &id003 !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ - 3
57
+ - 5
58
+ version: 0.3.5
59
+ type: :development
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ name: sinatra
63
+ prerelease: false
64
+ requirement: &id004 !ruby/object:Gem::Requirement
50
65
  requirements:
51
66
  - - ~>
52
67
  - !ruby/object:Gem::Version
@@ -55,25 +70,25 @@ dependencies:
55
70
  - 9
56
71
  version: "0.9"
57
72
  type: :runtime
58
- version_requirements: *id003
73
+ version_requirements: *id004
59
74
  - !ruby/object:Gem::Dependency
60
75
  name: rest-client
61
76
  prerelease: false
62
- requirement: &id004 !ruby/object:Gem::Requirement
77
+ requirement: &id005 !ruby/object:Gem::Requirement
63
78
  requirements:
64
79
  - - ~>
65
80
  - !ruby/object:Gem::Version
66
81
  segments:
67
82
  - 1
68
- - 2
83
+ - 4
69
84
  - 0
70
- version: 1.2.0
85
+ version: 1.4.0
71
86
  type: :runtime
72
- version_requirements: *id004
87
+ version_requirements: *id005
73
88
  - !ruby/object:Gem::Dependency
74
89
  name: yajl-ruby
75
90
  prerelease: false
76
- requirement: &id005 !ruby/object:Gem::Requirement
91
+ requirement: &id006 !ruby/object:Gem::Requirement
77
92
  requirements:
78
93
  - - ~>
79
94
  - !ruby/object:Gem::Version
@@ -82,11 +97,11 @@ dependencies:
82
97
  - 6
83
98
  version: "0.6"
84
99
  type: :runtime
85
- version_requirements: *id005
100
+ version_requirements: *id006
86
101
  - !ruby/object:Gem::Dependency
87
102
  name: term-ansicolor
88
103
  prerelease: false
89
- requirement: &id006 !ruby/object:Gem::Requirement
104
+ requirement: &id007 !ruby/object:Gem::Requirement
90
105
  requirements:
91
106
  - - ~>
92
107
  - !ruby/object:Gem::Version
@@ -95,11 +110,11 @@ dependencies:
95
110
  - 0
96
111
  version: "1.0"
97
112
  type: :runtime
98
- version_requirements: *id006
113
+ version_requirements: *id007
99
114
  - !ruby/object:Gem::Dependency
100
115
  name: launchy
101
116
  prerelease: false
102
- requirement: &id007 !ruby/object:Gem::Requirement
117
+ requirement: &id008 !ruby/object:Gem::Requirement
103
118
  requirements:
104
119
  - - ">="
105
120
  - !ruby/object:Gem::Version
@@ -109,11 +124,11 @@ dependencies:
109
124
  - 2
110
125
  version: 0.3.2
111
126
  type: :runtime
112
- version_requirements: *id007
127
+ version_requirements: *id008
113
128
  - !ruby/object:Gem::Dependency
114
129
  name: mechanize
115
130
  prerelease: false
116
- requirement: &id008 !ruby/object:Gem::Requirement
131
+ requirement: &id009 !ruby/object:Gem::Requirement
117
132
  requirements:
118
133
  - - ~>
119
134
  - !ruby/object:Gem::Version
@@ -123,32 +138,38 @@ dependencies:
123
138
  - 0
124
139
  version: 1.0.0
125
140
  type: :runtime
126
- version_requirements: *id008
141
+ version_requirements: *id009
127
142
  description: ""
128
143
  email: pedro@heroku.com
129
144
  executables:
130
145
  - kensa
131
146
  extensions: []
132
147
 
133
- extra_rdoc_files:
134
- - TODO
148
+ extra_rdoc_files: []
149
+
135
150
  files:
136
151
  - .gitignore
137
152
  - Rakefile
138
- - TODO
139
- - a-server.rb
140
153
  - bin/kensa
141
154
  - kensa.gemspec
142
155
  - lib/heroku/kensa.rb
143
- - server.rb
156
+ - lib/heroku/kensa/check.rb
157
+ - lib/heroku/kensa/client.rb
158
+ - lib/heroku/kensa/http.rb
159
+ - lib/heroku/kensa/manifest.rb
160
+ - lib/heroku/kensa/sso.rb
144
161
  - set-env.sh
162
+ - test/all_check_test.rb
145
163
  - test/deprovision_check.rb
146
164
  - test/helper.rb
147
165
  - test/manifest_check_test.rb
166
+ - test/manifest_test.rb
148
167
  - test/provision_check_test.rb
149
168
  - test/provision_response_check_test.rb
150
- - test/resources/test_server.rb
169
+ - test/resources/runner.rb
170
+ - test/resources/server.rb
151
171
  - test/sso_check_test.rb
172
+ - test/sso_test.rb
152
173
  has_rdoc: true
153
174
  homepage: http://heroku.com
154
175
  licenses: []
@@ -167,11 +188,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
188
  version: "0"
168
189
  required_rubygems_version: !ruby/object:Gem::Requirement
169
190
  requirements:
170
- - - ">="
191
+ - - ">"
171
192
  - !ruby/object:Gem::Version
172
193
  segments:
173
- - 0
174
- version: "0"
194
+ - 1
195
+ - 3
196
+ - 1
197
+ version: 1.3.1
175
198
  requirements: []
176
199
 
177
200
  rubyforge_project:
@@ -180,10 +203,14 @@ signing_key:
180
203
  specification_version: 3
181
204
  summary: ""
182
205
  test_files:
206
+ - test/all_check_test.rb
183
207
  - test/deprovision_check.rb
184
208
  - test/helper.rb
185
209
  - test/manifest_check_test.rb
210
+ - test/manifest_test.rb
186
211
  - test/provision_check_test.rb
187
212
  - test/provision_response_check_test.rb
188
- - test/resources/test_server.rb
213
+ - test/resources/runner.rb
214
+ - test/resources/server.rb
189
215
  - test/sso_check_test.rb
216
+ - test/sso_test.rb
data/TODO DELETED
@@ -1,8 +0,0 @@
1
-
2
- [ ] heroku-addon test -n delete # run specific test [create | delete | sharing]
3
- [ ] heroku-addon test # run full test suite
4
- [ ] heroku-addon repl command # runs create, set ENVs, then delete on exit
5
- [ ] heroku-addon push # push manifest to heroku
6
-
7
- [X] heroku-addon check # check correctnes of JSON
8
- [X] heroku-addon init # generate skeleton manifest
data/a-server.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'sinatra'
2
- require 'yajl'
3
- require 'restclient'
4
-
5
- post "/heroku/resources" do
6
- request.body.rewind
7
- input = Yajl::Parser.parse(request.body.read)
8
- resp = { :id => 123, :config => { "FOO" => "bar" } }
9
- #resp = { :id => 456 }
10
- json = Yajl::Encoder.encode(resp)
11
- fork do
12
- sleep 2
13
- p input
14
- RestClient.put(input["callback_url"], json)
15
- end
16
- "{}"
17
- end
18
-
19
- delete "/heroku/resources/:id" do
20
- "ok"
21
- end
data/server.rb DELETED
@@ -1,13 +0,0 @@
1
- require 'sinatra'
2
- require 'yajl'
3
- require 'restclient'
4
-
5
- post "/heroku/resources" do
6
- resp = { :id => 123, :config => { "FOO" => "bar" } }
7
- #resp = { :id => 123 }
8
- Yajl::Encoder.encode(resp)
9
- end
10
-
11
- delete "/heroku/resources/:id" do
12
- "ok"
13
- end