kensa 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -27,7 +27,7 @@ begin
27
27
  gemspec.add_dependency(%q<launchy>, [">= 0.3.2"])
28
28
  gemspec.add_dependency(%q<mechanize>, ["~> 1.0.0"])
29
29
 
30
- gemspec.version = '0.4.1'
30
+ gemspec.version = '0.4.2'
31
31
  end
32
32
  rescue LoadError
33
33
  puts "Jeweler not available. Install it with: gem install jeweler"
data/bin/kensa CHANGED
@@ -5,15 +5,18 @@ require 'term/ansicolor'
5
5
  require 'launchy'
6
6
  require 'heroku/kensa'
7
7
 
8
- fn="addon-manifest.json"
9
- async=false
10
- env="test"
8
+ fn = "addon-manifest.json"
9
+ options = {
10
+ :async => false,
11
+ :env => "test",
12
+ }
11
13
 
12
14
  ARGV.options do |o|
13
15
  o.on("-f file", "--file") {|filename| fn = filename }
16
+ o.on("--async") { options[:async] = true }
17
+ o.on("--production") { options[:env] = "production" }
18
+ o.on("--plan PLANID") { |plan| options[:plan] = plan }
14
19
  o.on("-h", "--help") { command = "help" }
15
- o.on("--async") { async = true }
16
- o.on("--production") { env = "production" }
17
20
  o.parse!
18
21
  end
19
22
 
@@ -84,26 +87,26 @@ when "test"
84
87
  run ManifestCheck, fn
85
88
  when "provision"
86
89
  run ManifestCheck, fn
87
- run ProvisionCheck, fn, :async => async, :env => env
90
+ run ProvisionCheck, fn, options
88
91
  when "deprovision"
89
92
  id = ARGV.shift || abort("! no id specified; see usage")
90
93
  run ManifestCheck, fn
91
- run DeprovisionCheck, fn, :id => id, :async => async, :env => env
94
+ run DeprovisionCheck, fn, options.merge(:id => id)
92
95
  when "sso"
93
96
  id = ARGV.shift || abort("! no id specified; see usage")
94
97
  run ManifestCheck, fn
95
- run SsoCheck, fn, :id => id, :env => env
98
+ run SsoCheck, fn, options.merge(:id => id)
96
99
  else
97
100
  abort "! Unknown test '#{check}'; see usage"
98
101
  end
99
102
  when "run"
100
103
  abort "! missing command to run; see usage" if ARGV.empty?
101
104
  run ManifestCheck, fn
102
- run AllCheck, fn, :args => ARGV, :async => async, :env => env
105
+ run AllCheck, fn, options.merge(:args => ARGV)
103
106
  when "sso"
104
107
  id = ARGV.shift || abort("! no id specified; see usage")
105
108
  data = Yajl::Parser.parse(resolve_manifest(fn)).merge(:id => id)
106
- sso = Sso.new(data)
109
+ sso = Sso.new(data.merge(options))
107
110
  puts "Opening #{sso.full_url}"
108
111
  Launchy.open sso.full_url
109
112
  else
@@ -127,6 +130,9 @@ OPTIONS
127
130
  --async
128
131
  Check provision call with async response.
129
132
 
133
+ --plan plan-id
134
+ Use the identified plan when doing provision calls
135
+
130
136
  COMMANDS
131
137
 
132
138
  init Creates a skeleton manifest
data/kensa.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kensa}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Blake Mizerany", "Pedro Belo", "Adam Wiggins"]
12
- s.date = %q{2010-04-07}
12
+ s.date = %q{2010-05-21}
13
13
  s.default_executable = %q{kensa}
14
14
  s.description = %q{}
15
15
  s.email = %q{pedro@heroku.com}
data/lib/heroku/kensa.rb CHANGED
@@ -251,7 +251,7 @@ EOJSON
251
251
  response = data[:provision_response]
252
252
  test "response"
253
253
  check "contains an id" do
254
- response.has_key?("id")
254
+ response.is_a?(Hash) && response.has_key?("id")
255
255
  end
256
256
 
257
257
  if response.has_key?("config")
@@ -272,7 +272,7 @@ EOJSON
272
272
  if v.is_a?(String)
273
273
  true
274
274
  else
275
- error "#{v.inspect} is not a string"
275
+ error "the key #{k} doesn't contain a string (#{v.inspect})"
276
276
  end
277
277
  end
278
278
  end
@@ -329,7 +329,7 @@ EOJSON
329
329
  body = RestClient::Resource.new(url, user, pass)[path].send(
330
330
  meth,
331
331
  *args
332
- )
332
+ ).to_s
333
333
 
334
334
  code = 200
335
335
  rescue RestClient::ExceptionWithResponse => boom
@@ -375,8 +375,7 @@ EOJSON
375
375
 
376
376
  payload = {
377
377
  :heroku_id => APPID,
378
- :appname => APPNAME,
379
- :plan => @data['plans'].first['id'],
378
+ :plan => @data[:plan] || @data['plans'].first['id'],
380
379
  :callback_url => callback
381
380
  }
382
381
 
@@ -455,7 +454,7 @@ EOJSON
455
454
  id = data[:id]
456
455
  raise ArgumentError, "No id specified" if id.nil?
457
456
 
458
- path = "/heroku/resources/#{id}"
457
+ path = "/heroku/resources/#{CGI::escape(id.to_s)}"
459
458
 
460
459
  test "DELETE #{path}"
461
460
  check "response" do
@@ -487,7 +486,8 @@ EOJSON
487
486
  def initialize(data)
488
487
  @id = data[:id]
489
488
  @salt = data['api']['sso_salt']
490
- @url = data["api"]["test"].chomp('/')
489
+ env = data[:env] || 'test'
490
+ @url = data["api"][env].chomp('/')
491
491
  end
492
492
 
493
493
  def path
@@ -5,46 +5,40 @@ class ProvisionCheckTest < Test::Unit::TestCase
5
5
 
6
6
  setup do
7
7
  @data = Manifest.skeleton
8
- @responses = [
9
- [200, to_json({ :id => 456 })],
10
- [401, "Unauthorized"]
11
- ]
8
+ @data['api']['username'] = 'test'
9
+ @data['api']['password'] = 'secret'
12
10
  end
13
11
 
14
12
  def check ; ProvisionCheck ; end
15
13
 
16
- test "valid on 200 for the regular check, and 401 for the auth check" do
17
- assert_valid do |check|
18
- stub :post, check, @responses
19
- end
14
+ test "working provision call" do
15
+ @data['api']['test'] += "working"
16
+ assert_valid
20
17
  end
21
18
 
22
- test "invalid JSON" do
23
- @responses[0] = [200, "---"]
24
- assert_invalid do |check|
25
- stub :post, check, @responses
26
- end
19
+ test "detects invalid JSON" do
20
+ @data['api']['test'] += "invalid-json"
21
+ assert_invalid
27
22
  end
28
23
 
29
- test "status other than 200" do
30
- @responses[0] = [500, to_json({ :id => 456 })]
31
- assert_invalid do |check|
32
- stub :post, check, @responses
33
- end
24
+ test "detects invalid response" do
25
+ @data['api']['test'] += "invalid-response"
26
+ assert_invalid
34
27
  end
35
28
 
36
- test "runs provision response check" do
37
- @responses[0] = [200, to_json({ :noid => 456 })]
38
- assert_invalid do |check|
39
- stub :post, check, @responses
40
- end
29
+ test "detects invalid status" do
30
+ @data['api']['test'] += "invalid-status"
31
+ assert_invalid
41
32
  end
42
33
 
43
- test "runs auth check" do
44
- @responses[1] = [200, to_json({ :id => 456 })]
45
- assert_invalid do |check|
46
- stub :post, check, @responses
47
- end
34
+ test "detects missing id" do
35
+ @data['api']['test'] += "invalid-missing-id"
36
+ assert_invalid
37
+ end
38
+
39
+ test "detects missing auth" do
40
+ @data['api']['test'] += "invalid-missing-auth"
41
+ assert_invalid
48
42
  end
49
43
 
50
44
  end
@@ -1,9 +1,22 @@
1
1
  require 'rubygems'
2
2
  require 'sinatra'
3
+ require 'json'
3
4
 
4
5
  enable :sessions
5
6
 
6
7
  helpers do
8
+ def heroku_only!
9
+ unless auth_heroku?
10
+ response['WWW-Authenticate'] = %(Basic realm="Kensa Test Server")
11
+ unauthorized!(401)
12
+ end
13
+ end
14
+
15
+ def auth_heroku?
16
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
17
+ @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['test', 'secret']
18
+ end
19
+
7
20
  def unauthorized!(status=403)
8
21
  throw(:halt, [status, "Not authorized\n"])
9
22
  end
@@ -18,6 +31,37 @@ helpers do
18
31
  end
19
32
  end
20
33
 
34
+ post '/working/heroku/resources' do
35
+ heroku_only!
36
+ { :id => 123 }.to_json
37
+ end
38
+
39
+ post '/invalid-json/heroku/resources' do
40
+ heroku_only!
41
+ 'invalidjson'
42
+ end
43
+
44
+ post '/invalid-response/heroku/resources' do
45
+ heroku_only!
46
+ nil.to_json
47
+ end
48
+
49
+ post '/invalid-status/heroku/resources' do
50
+ heroku_only!
51
+ status 422
52
+ { :id => 123 }.to_json
53
+ end
54
+
55
+ post '/invalid-missing-id/heroku/resources' do
56
+ heroku_only!
57
+ { :noid => 123 }.to_json
58
+ end
59
+
60
+ post '/invalid-missing-auth/heroku/resources' do
61
+ { :id => 123 }.to_json
62
+ end
63
+
64
+
21
65
  get '/working/heroku/resources/:id' do
22
66
  unauthorized! unless params[:id] && params[:token]
23
67
  unauthorized! unless params[:timestamp].to_i > (Time.now-60*2).to_i
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 1
9
- version: 0.4.1
8
+ - 2
9
+ version: 0.4.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Blake Mizerany
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-04-07 00:00:00 -07:00
19
+ date: 2010-05-21 00:00:00 -07:00
20
20
  default_executable: kensa
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency