vidibus-service 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,15 +5,14 @@ gem "vidibus-core_extensions"
5
5
  gem "vidibus-secure"
6
6
  gem "vidibus-uuid"
7
7
  gem "vidibus-validate_uri"
8
-
9
8
  gem "httparty"
10
9
  gem "json"
11
10
 
12
- # Development dependecies
13
- gem "jeweler"
14
- gem "rake"
15
- gem "rspec", "~> 2.0.0.beta.20"
16
- gem "rr"
17
- gem "relevance-rcov"
18
- gem "webmock"
19
-
11
+ group :development do
12
+ gem "jeweler"
13
+ gem "rake"
14
+ gem "rspec", "~> 2.0.0.beta.20"
15
+ gem "rr"
16
+ gem "relevance-rcov"
17
+ gem "webmock"
18
+ end
data/Gemfile.lock CHANGED
@@ -2,117 +2,115 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  abstract (1.0.0)
5
- actionmailer (3.0.0)
6
- actionpack (= 3.0.0)
7
- mail (~> 2.2.5)
8
- actionpack (3.0.0)
9
- activemodel (= 3.0.0)
10
- activesupport (= 3.0.0)
5
+ actionmailer (3.0.3)
6
+ actionpack (= 3.0.3)
7
+ mail (~> 2.2.9)
8
+ actionpack (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
11
11
  builder (~> 2.1.2)
12
12
  erubis (~> 2.6.6)
13
- i18n (~> 0.4.1)
13
+ i18n (~> 0.4)
14
14
  rack (~> 1.2.1)
15
- rack-mount (~> 0.6.12)
16
- rack-test (~> 0.5.4)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.6)
17
17
  tzinfo (~> 0.3.23)
18
- activemodel (3.0.0)
19
- activesupport (= 3.0.0)
18
+ activemodel (3.0.3)
19
+ activesupport (= 3.0.3)
20
20
  builder (~> 2.1.2)
21
- i18n (~> 0.4.1)
22
- activerecord (3.0.0)
23
- activemodel (= 3.0.0)
24
- activesupport (= 3.0.0)
25
- arel (~> 1.0.0)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.3)
23
+ activemodel (= 3.0.3)
24
+ activesupport (= 3.0.3)
25
+ arel (~> 2.0.2)
26
26
  tzinfo (~> 0.3.23)
27
- activeresource (3.0.0)
28
- activemodel (= 3.0.0)
29
- activesupport (= 3.0.0)
30
- activesupport (3.0.0)
31
- addressable (2.2.1)
32
- arel (1.0.1)
33
- activesupport (~> 3.0.0)
34
- bson (1.0.4)
27
+ activeresource (3.0.3)
28
+ activemodel (= 3.0.3)
29
+ activesupport (= 3.0.3)
30
+ activesupport (3.0.3)
31
+ addressable (2.2.2)
32
+ arel (2.0.6)
33
+ bson (1.1.4)
35
34
  builder (2.1.2)
36
35
  crack (0.1.8)
37
36
  diff-lcs (1.1.2)
38
37
  erubis (2.6.6)
39
38
  abstract (>= 1.0.0)
40
- gemcutter (0.6.1)
41
39
  git (1.2.5)
42
40
  httparty (0.6.1)
43
41
  crack (= 0.1.8)
44
- i18n (0.4.1)
45
- jeweler (1.4.0)
46
- gemcutter (>= 0.1.0)
42
+ i18n (0.5.0)
43
+ jeweler (1.5.1)
44
+ bundler (~> 1.0.0)
47
45
  git (>= 1.2.5)
48
- rubyforge (>= 2.0.0)
46
+ rake
49
47
  json (1.4.6)
50
- json_pure (1.4.6)
51
48
  macaddr (1.0.0)
52
- mail (2.2.6)
49
+ mail (2.2.12)
53
50
  activesupport (>= 2.3.6)
54
- mime-types
55
- treetop (>= 1.4.5)
51
+ i18n (>= 0.4.0)
52
+ mime-types (~> 1.16)
53
+ treetop (~> 1.4.8)
56
54
  mime-types (1.16)
57
- mongo (1.0.7)
58
- bson (>= 1.0.4)
59
- mongoid (2.0.0.beta.17)
60
- activemodel (~> 3.0.0)
61
- bson (= 1.0.4)
62
- mongo (= 1.0.7)
55
+ mongo (1.1.4)
56
+ bson (>= 1.1.1)
57
+ mongoid (2.0.0.beta.20)
58
+ activemodel (~> 3.0)
59
+ mongo (~> 1.1)
63
60
  tzinfo (~> 0.3.22)
64
61
  will_paginate (~> 3.0.pre)
65
62
  polyglot (0.3.1)
66
63
  rack (1.2.1)
67
64
  rack-mount (0.6.13)
68
65
  rack (>= 1.0.0)
69
- rack-test (0.5.4)
66
+ rack-test (0.5.6)
70
67
  rack (>= 1.0)
71
- rails (3.0.0)
72
- actionmailer (= 3.0.0)
73
- actionpack (= 3.0.0)
74
- activerecord (= 3.0.0)
75
- activeresource (= 3.0.0)
76
- activesupport (= 3.0.0)
77
- bundler (~> 1.0.0)
78
- railties (= 3.0.0)
79
- railties (3.0.0)
80
- actionpack (= 3.0.0)
81
- activesupport (= 3.0.0)
82
- rake (>= 0.8.4)
83
- thor (~> 0.14.0)
68
+ rails (3.0.3)
69
+ actionmailer (= 3.0.3)
70
+ actionpack (= 3.0.3)
71
+ activerecord (= 3.0.3)
72
+ activeresource (= 3.0.3)
73
+ activesupport (= 3.0.3)
74
+ bundler (~> 1.0)
75
+ railties (= 3.0.3)
76
+ railties (3.0.3)
77
+ actionpack (= 3.0.3)
78
+ activesupport (= 3.0.3)
79
+ rake (>= 0.8.7)
80
+ thor (~> 0.14.4)
84
81
  rake (0.8.7)
85
82
  relevance-rcov (0.9.2.1)
86
- rr (1.0.0)
87
- rspec (2.0.0.beta.20)
88
- rspec-core (= 2.0.0.beta.20)
89
- rspec-expectations (= 2.0.0.beta.20)
90
- rspec-mocks (= 2.0.0.beta.20)
91
- rspec-core (2.0.0.beta.20)
92
- rspec-expectations (2.0.0.beta.20)
83
+ rr (1.0.2)
84
+ rspec (2.0.1)
85
+ rspec-core (~> 2.0.1)
86
+ rspec-expectations (~> 2.0.1)
87
+ rspec-mocks (~> 2.0.1)
88
+ rspec-core (2.0.1)
89
+ rspec-expectations (2.0.1)
93
90
  diff-lcs (>= 1.1.2)
94
- rspec-mocks (2.0.0.beta.20)
95
- rubyforge (2.0.4)
96
- json_pure (>= 1.1.7)
97
- thor (0.14.0)
98
- treetop (1.4.8)
91
+ rspec-mocks (2.0.1)
92
+ rspec-core (~> 2.0.1)
93
+ rspec-expectations (~> 2.0.1)
94
+ thor (0.14.6)
95
+ treetop (1.4.9)
99
96
  polyglot (>= 0.3.1)
100
97
  tzinfo (0.3.23)
101
98
  uuid (2.3.1)
102
99
  macaddr (~> 1.0)
103
- vidibus-core_extensions (0.3.5)
104
- vidibus-secure (0.0.1)
100
+ vidibus-core_extensions (0.3.12)
101
+ vidibus-secure (0.0.3)
105
102
  activesupport (~> 3.0.0)
106
- mongoid (~> 2.0.0.beta.17)
103
+ mongoid (~> 2.0.0.beta.20)
107
104
  rack
108
105
  vidibus-core_extensions
109
- vidibus-uuid (0.3.7)
110
- mongoid (~> 2.0.0.beta.17)
106
+ vidibus-uuid (0.3.8)
107
+ mongoid (~> 2.0.0.beta.20)
111
108
  uuid (~> 2.3.1)
112
- vidibus-validate_uri (0.1.1)
113
- rails (~> 3.0.0.rc)
114
- webmock (1.3.5)
115
- addressable (>= 2.1.1)
109
+ vidibus-validate_uri (0.1.3)
110
+ rails (~> 3.0.0)
111
+ rails (~> 3.0.0)
112
+ webmock (1.6.1)
113
+ addressable (>= 2.2.2)
116
114
  crack (>= 0.1.7)
117
115
  will_paginate (3.0.pre2)
118
116
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Andre Pankratz
1
+ Copyright (c) 2010 Andre Pankratz
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  Description goes here.
4
4
 
5
+
6
+ == Requirements
7
+
8
+ In order to work properly this gem needs the route /connector to call a Rack app. Usually this route gets provided automatically but that may fail if your application has some sort of catch-all route. To check if the route works as expected, just call http://yourapp.com/connector and expect an error message like +This service has not been configured yet. Use your Connector to set it up.+
9
+
10
+ If you don't see this error message, add the route manually at the top of your routes.rb:
11
+
12
+ match "/connector" => Vidibus::Service::ConnectorApp
13
+
14
+
5
15
  == Note on Patches/Pull Requests
6
16
 
7
17
  * Fork the project.
data/Rakefile CHANGED
@@ -13,13 +13,6 @@ begin
13
13
  gem.email = "andre@vidibus.com"
14
14
  gem.homepage = "http://github.com/vidibus/vidibus-service"
15
15
  gem.authors = ["Andre Pankratz"]
16
- gem.add_dependency "mongoid", "~> 2.0.0.beta.20"
17
- gem.add_dependency "vidibus-core_extensions"
18
- gem.add_dependency "vidibus-uuid"
19
- gem.add_dependency "vidibus-secure"
20
- gem.add_dependency "vidibus-validate_uri"
21
- gem.add_dependency "httparty"
22
- gem.add_dependency "json"
23
16
  end
24
17
  Jeweler::GemcutterTasks.new
25
18
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.3
@@ -4,13 +4,13 @@ module Vidibus
4
4
  module Service
5
5
  class ConnectorApp
6
6
  class SignatureError < StandardError; end
7
+ class ValidationError < StandardError; end
8
+ class SetupError < StandardError; end
7
9
 
8
10
  def self.call(env)
9
11
  self.new.call(env)
10
12
  end
11
13
 
12
- # This is just a rack endpoint for Remote authentication. It will be called
13
- # by the Remote after requesting an authentication code.
14
14
  def call(env)
15
15
  @request = Rack::Request.new(env)
16
16
  unless @request.path == "/connector"
@@ -27,39 +27,16 @@ module Vidibus
27
27
  protected
28
28
 
29
29
  # Creates this service and, unless it has already been set up, a Connector service.
30
- # Once this service has been created, a secret will be traded for given nonce.
30
+ # Once this service has been created, a secret will be traded for the given nonce.
31
31
  def post
32
- unless this = service.where(:this => true, :realm => nil).first
33
- unless connector = service.local(:connector)
34
- connector_data = @request.params["connector"] or
35
- return response(:error => "No Connector data given.")
36
- connector = service.new(connector_data.merge(:function => "connector"))
37
- unless connector.save
38
- return response(:error => "Setting up the Connector failed: #{connector.errors.full_messages}")
39
- end
40
- end
41
- this_data = @request.params["this"] or
42
- return response(:error => "No data for this service given.")
43
- this = service.new(this_data.merge(:this => true))
44
- this.secret = "this is just a mock"
45
- if this.valid?
46
- nonce = @request.params["this"]["nonce"]
47
- unless nonce == ""
48
- uri = "#{connector.url}/services/#{this.uuid}/secret"
49
- res = HTTParty.get(uri, :format => :json)
50
- end
51
- unless nonce.to_s.length > 5 and Vidibus::Secure.sign(res["secret"], nonce) == res["sign"]
52
- return response(:error => "Nonce is invalid.")
53
- end
54
- this.secret = Vidibus::Secure.decrypt(res["secret"], nonce)
55
- if this.save
56
- return response({:success => "Setup successful"}, 201)
57
- end
58
- end
59
- response(:error => "Setting up this service failed: #{this.errors.full_messages}")
60
- else
61
- response(:error => "Service has already been set up.")
32
+ if service.where(:this => true, :realm => nil).first
33
+ raise SetupError, "This service has already been set up."
62
34
  end
35
+ service.local(:connector) || create_connector!
36
+ create_this!
37
+ response({:success => "Setup successful"}, 201)
38
+ rescue SetupError => e
39
+ response(:error => e.message)
63
40
  end
64
41
 
65
42
  # Returns settings of this and Connector.
@@ -77,14 +54,18 @@ module Vidibus
77
54
  end
78
55
 
79
56
  # Updates data of given services.
80
- # If a service does not exist, it will be created.
81
57
  def put
82
58
  verify_request!
83
- for function, attributes in @request.params.except("sign")
84
- _service = service.local(function) || service.new(:function => function)
59
+ for uuid, attributes in @request.params.except("sign")
60
+ unless Vidibus::Uuid.validate(uuid)
61
+ raise "Updating failed: '#{uuid}' is not a valid UUID."
62
+ end
63
+ unless _service = service.where(:uuid => uuid).first
64
+ raise "Updating service #{uuid} failed: This service does not exist!"
65
+ end
85
66
  _service.attributes = attributes
86
67
  unless _service.save
87
- return response(:error => "Updating #{function} failed: #{_service.errors.full_messages}")
68
+ raise "Updating service #{uuid} failed: #{_service.errors.full_messages}"
88
69
  end
89
70
  end
90
71
  response(:success => "Services updated.")
@@ -95,10 +76,14 @@ module Vidibus
95
76
  # Deletes services by their UUID.
96
77
  def delete
97
78
  verify_request!
98
- raise ArgumentError.new("Provide list of :uuids") unless uuids = @request.params["uuids"]
79
+ unless uuids = @request.params["uuids"]
80
+ raise "Provide list of UUIDs of services to delete."
81
+ end
99
82
  for uuid in uuids
100
- if found = service.where(:uuid => uuid).first
101
- found.destroy
83
+ _service = service.where(:uuid => uuid).first
84
+ next unless _service
85
+ unless _service.destroy
86
+ raise "Deleting service #{uuid} failed: #{_service.errors.full_messages}"
102
87
  end
103
88
  end
104
89
  response(:success => "Services have been deleted.")
@@ -108,8 +93,9 @@ module Vidibus
108
93
 
109
94
  # Verifies that signature is valid.
110
95
  def verify_request!
111
- Vidibus::Secure.verify_request(@request.request_method, @request.url, @request.params, this.secret) or
96
+ unless Vidibus::Secure.verify_request(@request.request_method, @request.url, @request.params, this.secret)
112
97
  raise SignatureError.new("Invalid signature.")
98
+ end
113
99
  end
114
100
 
115
101
  # Renders response.
@@ -149,6 +135,56 @@ module Vidibus
149
135
  def connector
150
136
  @connector ||= service.connector
151
137
  end
138
+
139
+ # Creates Connector service from params containing +function+ "connector".
140
+ def create_connector!
141
+ uuid, data = @request.params.select {|k,v| v["function"] == "connector"}.first
142
+ raise SetupError, "No Connector data given." unless data
143
+ connector = service.new(data)
144
+ unless connector.save
145
+ raise SetupError, "Setting up the Connector failed: #{connector.errors.full_messages}"
146
+ end
147
+ connector
148
+ end
149
+
150
+ # Creates this service from params containing "this".
151
+ def create_this!
152
+ uuid, data = @request.params.select {|k,v| v["this"] == "true"}.first
153
+ raise SetupError, "No data given for this service." unless data
154
+
155
+ this = service.new(data)
156
+ this.valid?
157
+ raise ValidationError unless this.errors.except(:secret).empty?
158
+
159
+ set_secret!(this)
160
+ this.save or raise ValidationError
161
+ rescue ValidationError
162
+ raise SetupError, "Setting up this service failed: #{this.errors.full_messages}"
163
+ end
164
+
165
+ # Trades given nonce for secret.
166
+ def set_secret!(service)
167
+ raise SetupError, "Setting a secret for this service is not allowed!" if service.secret
168
+ nonce = service.nonce
169
+ raise SetupError, "No nonce given." unless nonce and nonce != ""
170
+
171
+ fetched = fetch_secret(service)
172
+ service.secret = decrypt_secret!(fetched["secret"], nonce, fetched["sign"])
173
+ end
174
+
175
+ # Requests encrypted secret for given service from Connector.
176
+ def fetch_secret(service)
177
+ uri = "#{connector.url}/services/#{service.uuid}/secret"
178
+ HTTParty.get(uri, :format => :json)
179
+ end
180
+
181
+ # Decrypts secret with nonce.++
182
+ def decrypt_secret!(secret, nonce, sign)
183
+ unless Vidibus::Secure.sign(secret, nonce) == sign
184
+ raise SetupError, "Nonce is invalid."
185
+ end
186
+ Vidibus::Secure.decrypt(secret, nonce)
187
+ end
152
188
  end
153
189
  end
154
190
  end
@@ -14,6 +14,7 @@ module Vidibus
14
14
  field :realm_uuid
15
15
  field :this, :type => Boolean
16
16
 
17
+ attr_accessor :nonce
17
18
  attr_encrypted :secret
18
19
 
19
20
  validates :url, :uri => {:protocol => [:http, :https], :accessible => false}
data/spec/spec_helper.rb CHANGED
@@ -19,7 +19,7 @@ Mongoid.configure do |config|
19
19
  end
20
20
 
21
21
  RSpec.configure do |config|
22
- config.include WebMock
22
+ config.include WebMock::API
23
23
  config.mock_with :rr
24
24
  config.before(:each) do
25
25
  Mongoid.master.collections.select {|c| c.name !~ /system/}.each(&:drop)
@@ -2,11 +2,19 @@ require "spec_helper.rb"
2
2
 
3
3
  describe "Vidibus::Service::ConnectorApp" do
4
4
  include Rack::Test::Methods
5
+ let(:this_uuid) {"344b4b8088fb012dd3e558b035f038ab"}
6
+ let(:this_uri) {"https://connector.local/services/#{this_uuid}/secret"}
7
+ let(:connector_uuid) {"60dfef509a8e012d599558b035f038ab"}
5
8
 
6
- let(:this_params) { {"uuid" => "344b4b8088fb012dd3e558b035f038ab", "url" => "http://manager.local", "function" => "manager"} }
7
- let(:connector_params) { {"uuid" => "60dfef509a8e012d599558b035f038ab", "url" => "https://connector.local"} }
8
- let(:this) { Service.create!(this_params.merge(:secret => "EaDai5nz16DbQTWQuuFdd4WcAiZYRPDwZTn2IQeXbPE4yBg3rr", :realm_uuid => nil, :this => true)) }
9
- let(:connector) { Service.create!(connector_params.merge(:function => "connector", :secret => nil, :realm_uuid => nil)) }
9
+ let(:nonce) {"hkO2ssb28Gks19s9h2hdhbBs83hdis"}
10
+ let(:secret) {"EaDai5nz16DbQTWQuuFdd4WcAiZYRPDwZTn2IQeXbPE4yBg3rr"}
11
+ let(:encrypted_secret) {Vidibus::Secure.encrypt(secret, nonce)}
12
+ let(:signature) {Vidibus::Secure.sign(encrypted_secret, nonce)}
13
+
14
+ let(:this_params) {{:uuid => this_uuid, :url => "http://manager.local", :function => "manager", :this => true}}
15
+ let(:connector_params) {{:uuid => connector_uuid, :url => "https://connector.local", :function => "connector", :secret => nil, :realm_uuid => nil}}
16
+ let(:this) {Service.create!(this_params.merge(:secret => "EaDai5nz16DbQTWQuuFdd4WcAiZYRPDwZTn2IQeXbPE4yBg3rr", :realm_uuid => nil))}
17
+ let(:connector) {Service.create!(connector_params)}
10
18
 
11
19
  def app
12
20
  @app ||= Vidibus::Service::ConnectorApp
@@ -70,83 +78,107 @@ describe "Vidibus::Service::ConnectorApp" do
70
78
  this
71
79
  post "http://manager/connector", {}
72
80
  last_response.status.should eql(400)
73
- last_response.body.should eql(%({"error":"Service has already been set up."}))
81
+ last_response.body.should match("This service has already been set up.")
74
82
  end
75
83
 
76
- it "should require Connector params" do
77
- post "http://manager.local/connector"
78
- last_response.status.should eql(400)
79
- last_response.body.should eql(%({"error":"No Connector data given."}))
84
+ context "without Connector or Connector params" do
85
+ it "should require Connector params" do
86
+ post "http://manager.local/connector"
87
+ last_response.status.should eql(400)
88
+ last_response.body.should match("No Connector data given.")
89
+ end
80
90
  end
81
91
 
82
- it "should fail if Connector data is invalid" do
83
- post "http://manager.local/connector", {:connector => {:some => "thing"}}
84
- last_response.status.should eql(400)
85
- last_response.body.should match("Setting up the Connector failed:")
86
- end
92
+ context "with Connector params" do
93
+ before {stub.any_instance_of(Vidibus::Service::ConnectorApp).create_this!}
94
+
95
+ it "should fail if params are invalid given" do
96
+ post "http://manager.local/connector", {connector_uuid => connector_params.except(:url)}
97
+ last_response.status.should eql(400)
98
+ last_response.body.should match("Setting up the Connector failed:")
99
+ end
87
100
 
88
- it "should set up a Connector" do
89
- mock(::Service).new(connector_params.merge(:function => "connector"))
90
- expect {
91
- post "http://manager.local/connector", {:connector => connector_params}
92
- }.to raise_error(NoMethodError, "undefined method `save' for nil:NilClass")
101
+ it "should set up a Connector with valid params" do
102
+ post "http://manager.local/connector", {connector_uuid => connector_params}
103
+ last_response.status.should eql(201)
104
+ connector = Service.where(:uuid => connector_params[:uuid]).first
105
+ connector.should be_a(Service)
106
+ end
107
+
108
+ it "should accept any value as key" do
109
+ post "http://manager.local/connector", {"something" => connector_params}
110
+ last_response.status.should eql(201)
111
+ end
112
+
113
+ it "should not create another connector if one already exists" do
114
+ connector
115
+ post "http://manager.local/connector", {connector_uuid => connector_params}
116
+ last_response.status.should eql(201)
117
+ end
93
118
  end
94
119
 
95
- context "with Connector or Connector params" do
120
+ context "with existing Connector" do
121
+ let(:secret_data) {{"secret" => encrypted_secret, "sign" => signature}}
122
+ let(:stub_secret_request!) {stub(HTTParty).get(this_uri, :format => :json) {secret_data}}
96
123
  before { connector }
97
124
 
98
125
  it "should not require Connector params if a Connector is present" do
99
126
  post "http://manager.local/connector"
100
- last_response.body.should_not eql(%({"error":"No Connector data given."}))
127
+ last_response.body.should_not match("No Connector data given.")
101
128
  end
102
129
 
103
130
  it "should require params for this service" do
104
131
  post "http://manager.local/connector"
105
132
  last_response.status.should eql(400)
106
- last_response.body.should eql(%({"error":"No data for this service given."}))
133
+ last_response.body.should match("No data given for this service.")
107
134
  end
108
135
 
109
136
  it "should fail if params for this service are invalid" do
110
- post "http://manager.local/connector", {:this => {:some => "thing"}}
137
+ post "http://manager.local/connector", {this_uuid => this_params.except(:function)}
111
138
  last_response.status.should eql(400)
112
139
  last_response.body.should match("Setting up this service failed:")
113
140
  end
114
141
 
115
- it "should set up this Service" do
116
- mock(::Service).new(this_params.merge(:this => true))
117
- expect {
118
- post "http://manager.local/connector", {:this => this_params}
119
- }.to raise_error(NoMethodError, "undefined method `secret=' for nil:NilClass")
142
+ it "should fail if a secret is given" do
143
+ post "http://manager.local/connector", {this_uuid => this_params.merge(:secret => "something")}
144
+ last_response.status.should eql(400)
145
+ last_response.body.should match("Setting a secret for this service is not allowed!")
146
+ end
147
+
148
+ it "should fail unless a nonce is given" do
149
+ post "http://manager.local/connector", {this_uuid => this_params}
150
+ last_response.status.should eql(400)
151
+ last_response.body.should match("No nonce given.")
120
152
  end
121
153
 
122
154
  it "should request a secret for this Service" do
123
- uri = "https://connector.local/services/#{this_params["uuid"]}/secret"
124
- stub_http_request(:get, uri).to_return(:status => 200)
125
- post "http://manager.local/connector", {:this => this_params}
155
+ mock(HTTParty).get(this_uri, :format => :json) {{}}
156
+ stub.any_instance_of(Vidibus::Service::ConnectorApp).decrypt_secret! {"ok"}
157
+ post "http://manager.local/connector", {this_uuid => this_params.merge(:nonce => nonce)}
126
158
  end
127
159
 
128
- it "should require a valid nonce to decrypt requested secret" do
129
- uri = "https://connector.local/services/#{this_params["uuid"]}/secret"
130
- params = {}
131
- stub_http_request(:get, uri).to_return(:status => 200, :body => %({"secret":"something","sign":"else"}))
132
- post "http://manager.local/connector", {:this => this_params.merge("nonce" => "invalid")}
160
+ it "should fail if sign cannot be validated with nonce" do
161
+ stub_secret_request!
162
+ post "http://manager.local/connector", {this_uuid => this_params.merge(:nonce => "invalid")}
133
163
  last_response.status.should eql(400)
134
164
  last_response.body.should match("Nonce is invalid.")
135
165
  end
136
166
 
137
- it "should decrypt requested secret and store it on the service object" do
138
- nonce = "hkO2ssb28Gks19s9h2hdhbBs83hdis"
139
- secret = "EaDai5nz16DbQTWQuuFdd4WcAiZYRPDwZTn2IQeXbPE4yBg3rr"
140
- encrypted_secret = Vidibus::Secure.encrypt(secret, nonce)
141
- signature = Vidibus::Secure.sign(encrypted_secret, nonce)
142
- uri = "https://connector.local/services/#{this_params["uuid"]}/secret"
143
- params = {:secret => encrypted_secret, :sign => signature}
144
- stub_http_request(:get, uri).to_return(:status => 200, :body => params.to_json)
145
- post "http://manager.local/connector", {:this => this_params.merge("nonce" => nonce)}
167
+ it "should decrypt the secret with a valid nonce" do
168
+ stub_secret_request!
169
+ mock.any_instance_of(Service).secret=(secret)
170
+ post "http://manager.local/connector", {this_uuid => this_params.merge(:nonce => nonce)}
171
+ end
172
+
173
+ it "should set up this Service with valid params" do
174
+ stub_secret_request!
175
+ post "http://manager.local/connector", {connector_uuid => this_params.merge(:nonce => nonce)}
176
+ stub(HTTParty).get(this_uri, :format => :json) {secret_data}
146
177
  last_response.status.should eql(201)
147
- this = ::Service.where(:this => true).first
148
- this.should be_a(::Service)
178
+ this = Service.where(:this => true).first
179
+ this.should be_a(Service)
149
180
  this.secret.should eql(secret)
181
+ this.url.should eql("http://manager.local")
150
182
  end
151
183
  end
152
184
  end
@@ -180,26 +212,33 @@ describe "Vidibus::Service::ConnectorApp" do
180
212
  it "should update existing services" do
181
213
  this and connector
182
214
  url = "http://newconnector.local"
183
- signed_request(:put, "http://manager.local/connector", {:connector => {:url => url}})
215
+ signed_request(:put, "http://manager.local/connector", {connector.uuid => {:url => url}})
184
216
  last_response.status.should eql(200)
185
217
  Service.local(:connector).url.should eql(url)
186
218
  end
187
219
 
188
- it "should fail if invalid data are given" do
220
+ it "should fail if no uuid is given" do
189
221
  this and connector
190
222
  url = "http://newconnector.local"
191
- signed_request(:put, "http://manager.local/connector", {:connector => {:secret => "not allowed"}})
223
+ signed_request(:put, "http://manager.local/connector", {:url => url})
192
224
  last_response.status.should eql(400)
193
- last_response.body.should match("Updating connector failed:")
225
+ last_response.body.should match("Updating failed: 'url' is not a valid UUID.")
194
226
  end
195
227
 
196
- it "should create new services" do
228
+ it "should fail if an invalid uuid is given" do
197
229
  this and connector
198
230
  url = "http://newconnector.local"
199
- signed_request(:put, "http://manager.local/connector",
200
- {:uploader => {:url => "http://uploader.local", :uuid => "c0861d609247012d0a8b58b035f038ab", :secret => "A7q8Vzxgrk9xrw2FCnvV4bv01UP/LBUUM0lIGDmMcB2GsBTIqx", :realm_uuid => "12ab69f099a4012d4df558b035f038ab"}})
201
- last_response.status.should eql(200)
202
- Service.local(:uploader, "12ab69f099a4012d4df558b035f038ab").url.should eql("http://uploader.local")
231
+ signed_request(:put, "http://manager.local/connector", {"c0861d609247012d0a8b58b035f038ab" => {:url => url}})
232
+ last_response.status.should eql(400)
233
+ last_response.body.should match("Updating service c0861d609247012d0a8b58b035f038ab failed:")
234
+ end
235
+
236
+ it "should fail if invalid data is given" do
237
+ this and connector
238
+ url = "http://newconnector.local"
239
+ signed_request(:put, "http://manager.local/connector", {connector.uuid => {:secret => "not allowed"}})
240
+ last_response.status.should eql(400)
241
+ last_response.body.should match("Updating service 60dfef509a8e012d599558b035f038ab failed:")
203
242
  end
204
243
  end
205
244
 
@@ -227,19 +266,27 @@ describe "Vidibus::Service::ConnectorApp" do
227
266
  this and connector
228
267
  signed_request(:delete, "http://manager.local/connector", {})
229
268
  last_response.status.should eql(400)
230
- last_response.body.should eql(%({"error":"Provide list of :uuids"}))
269
+ last_response.body.should eql(%({"error":"Provide list of UUIDs of services to delete."}))
270
+ end
271
+
272
+ it "should fail if deleting of a service fails" do
273
+ this and connector
274
+ stub.any_instance_of(Service).destroy {false} # Would be nice: errors.add(:base, "Failed")
275
+ signed_request(:delete, "http://manager.local/connector", {:uuids =>[connector_uuid]})
276
+ last_response.status.should eql(400)
277
+ last_response.body.should eql(%({"error":"Deleting service 60dfef509a8e012d599558b035f038ab failed: "}))
231
278
  end
232
279
 
233
280
  it "should delete services given by UUID" do
234
281
  this and connector
235
- signed_request(:delete, "http://manager.local/connector", {:uuids =>["60dfef509a8e012d599558b035f038ab"]})
282
+ signed_request(:delete, "http://manager.local/connector", {:uuids =>[connector_uuid]})
236
283
  last_response.status.should eql(200)
237
284
  Service.local(:connector).should be_nil
238
285
  end
239
286
 
240
287
  it "should not care if any given UUID is invalid" do
241
288
  this and connector
242
- signed_request(:delete, "http://manager.local/connector", {:uuids =>["invalid", "60dfef509a8e012d599558b035f038ab"]})
289
+ signed_request(:delete, "http://manager.local/connector", {:uuids =>["invalid", connector_uuid]})
243
290
  last_response.status.should eql(200)
244
291
  end
245
292
  end
@@ -1,61 +1,59 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{vidibus-service}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andre Pankratz"]
12
- s.date = %q{2010-09-23}
12
+ s.date = %q{2010-12-08}
13
13
  s.description = %q{Description...}
14
14
  s.email = %q{andre@vidibus.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".bundle/config",
21
- ".document",
22
- ".gitignore",
23
- ".rspec",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE",
27
- "README.rdoc",
28
- "Rakefile",
29
- "VERSION",
30
- "app/models/service.rb",
31
- "config/locales/en.yml",
32
- "config/routes.rb",
33
- "lib/vidibus-service.rb",
34
- "lib/vidibus/service.rb",
35
- "lib/vidibus/service/client.rb",
36
- "lib/vidibus/service/connector_app.rb",
37
- "lib/vidibus/service/controller_validations.rb",
38
- "lib/vidibus/service/mongoid.rb",
39
- "spec/spec_helper.rb",
40
- "spec/vidibus/service/client_spec.rb",
41
- "spec/vidibus/service/connector_app_spec.rb",
42
- "spec/vidibus/service/controller_validations_spec.rb",
43
- "spec/vidibus/service/mongoid_spec.rb",
44
- "spec/vidibus/service_spec.rb",
45
- "vidibus-service.gemspec"
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "app/models/service.rb",
30
+ "config/locales/en.yml",
31
+ "config/routes.rb",
32
+ "lib/vidibus-service.rb",
33
+ "lib/vidibus/service.rb",
34
+ "lib/vidibus/service/client.rb",
35
+ "lib/vidibus/service/connector_app.rb",
36
+ "lib/vidibus/service/controller_validations.rb",
37
+ "lib/vidibus/service/mongoid.rb",
38
+ "spec/spec_helper.rb",
39
+ "spec/vidibus/service/client_spec.rb",
40
+ "spec/vidibus/service/connector_app_spec.rb",
41
+ "spec/vidibus/service/controller_validations_spec.rb",
42
+ "spec/vidibus/service/mongoid_spec.rb",
43
+ "spec/vidibus/service_spec.rb",
44
+ "vidibus-service.gemspec"
46
45
  ]
47
46
  s.homepage = %q{http://github.com/vidibus/vidibus-service}
48
- s.rdoc_options = ["--charset=UTF-8"]
49
47
  s.require_paths = ["lib"]
50
48
  s.rubygems_version = %q{1.3.7}
51
49
  s.summary = %q{Provides tools for Vidibus services}
52
50
  s.test_files = [
53
51
  "spec/spec_helper.rb",
54
- "spec/vidibus/service/client_spec.rb",
55
- "spec/vidibus/service/connector_app_spec.rb",
56
- "spec/vidibus/service/controller_validations_spec.rb",
57
- "spec/vidibus/service/mongoid_spec.rb",
58
- "spec/vidibus/service_spec.rb"
52
+ "spec/vidibus/service/client_spec.rb",
53
+ "spec/vidibus/service/connector_app_spec.rb",
54
+ "spec/vidibus/service/controller_validations_spec.rb",
55
+ "spec/vidibus/service/mongoid_spec.rb",
56
+ "spec/vidibus/service_spec.rb"
59
57
  ]
60
58
 
61
59
  if s.respond_to? :specification_version then
@@ -65,28 +63,46 @@ Gem::Specification.new do |s|
65
63
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
64
  s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0.beta.20"])
67
65
  s.add_runtime_dependency(%q<vidibus-core_extensions>, [">= 0"])
68
- s.add_runtime_dependency(%q<vidibus-uuid>, [">= 0"])
69
66
  s.add_runtime_dependency(%q<vidibus-secure>, [">= 0"])
67
+ s.add_runtime_dependency(%q<vidibus-uuid>, [">= 0"])
70
68
  s.add_runtime_dependency(%q<vidibus-validate_uri>, [">= 0"])
71
69
  s.add_runtime_dependency(%q<httparty>, [">= 0"])
72
70
  s.add_runtime_dependency(%q<json>, [">= 0"])
71
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
72
+ s.add_development_dependency(%q<rake>, [">= 0"])
73
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.20"])
74
+ s.add_development_dependency(%q<rr>, [">= 0"])
75
+ s.add_development_dependency(%q<relevance-rcov>, [">= 0"])
76
+ s.add_development_dependency(%q<webmock>, [">= 0"])
73
77
  else
74
78
  s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.20"])
75
79
  s.add_dependency(%q<vidibus-core_extensions>, [">= 0"])
76
- s.add_dependency(%q<vidibus-uuid>, [">= 0"])
77
80
  s.add_dependency(%q<vidibus-secure>, [">= 0"])
81
+ s.add_dependency(%q<vidibus-uuid>, [">= 0"])
78
82
  s.add_dependency(%q<vidibus-validate_uri>, [">= 0"])
79
83
  s.add_dependency(%q<httparty>, [">= 0"])
80
84
  s.add_dependency(%q<json>, [">= 0"])
85
+ s.add_dependency(%q<jeweler>, [">= 0"])
86
+ s.add_dependency(%q<rake>, [">= 0"])
87
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.20"])
88
+ s.add_dependency(%q<rr>, [">= 0"])
89
+ s.add_dependency(%q<relevance-rcov>, [">= 0"])
90
+ s.add_dependency(%q<webmock>, [">= 0"])
81
91
  end
82
92
  else
83
93
  s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.20"])
84
94
  s.add_dependency(%q<vidibus-core_extensions>, [">= 0"])
85
- s.add_dependency(%q<vidibus-uuid>, [">= 0"])
86
95
  s.add_dependency(%q<vidibus-secure>, [">= 0"])
96
+ s.add_dependency(%q<vidibus-uuid>, [">= 0"])
87
97
  s.add_dependency(%q<vidibus-validate_uri>, [">= 0"])
88
98
  s.add_dependency(%q<httparty>, [">= 0"])
89
99
  s.add_dependency(%q<json>, [">= 0"])
100
+ s.add_dependency(%q<jeweler>, [">= 0"])
101
+ s.add_dependency(%q<rake>, [">= 0"])
102
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.20"])
103
+ s.add_dependency(%q<rr>, [">= 0"])
104
+ s.add_dependency(%q<relevance-rcov>, [">= 0"])
105
+ s.add_dependency(%q<webmock>, [">= 0"])
90
106
  end
91
107
  end
92
108
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-service
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andre Pankratz
@@ -15,13 +15,14 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-23 00:00:00 +02:00
18
+ date: 2010-12-08 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: mongoid
22
+ type: :runtime
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ name: mongoid
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
27
28
  - - ~>
@@ -34,12 +35,12 @@ dependencies:
34
35
  - beta
35
36
  - 20
36
37
  version: 2.0.0.beta.20
37
- type: :runtime
38
- version_requirements: *id001
38
+ requirement: *id001
39
39
  - !ruby/object:Gem::Dependency
40
- name: vidibus-core_extensions
40
+ type: :runtime
41
41
  prerelease: false
42
- requirement: &id002 !ruby/object:Gem::Requirement
42
+ name: vidibus-core_extensions
43
+ version_requirements: &id002 !ruby/object:Gem::Requirement
43
44
  none: false
44
45
  requirements:
45
46
  - - ">="
@@ -48,12 +49,26 @@ dependencies:
48
49
  segments:
49
50
  - 0
50
51
  version: "0"
52
+ requirement: *id002
53
+ - !ruby/object:Gem::Dependency
51
54
  type: :runtime
52
- version_requirements: *id002
55
+ prerelease: false
56
+ name: vidibus-secure
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirement: *id003
53
67
  - !ruby/object:Gem::Dependency
54
- name: vidibus-uuid
68
+ type: :runtime
55
69
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
70
+ name: vidibus-uuid
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
57
72
  none: false
58
73
  requirements:
59
74
  - - ">="
@@ -62,12 +77,26 @@ dependencies:
62
77
  segments:
63
78
  - 0
64
79
  version: "0"
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
65
82
  type: :runtime
66
- version_requirements: *id003
83
+ prerelease: false
84
+ name: vidibus-validate_uri
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirement: *id005
67
95
  - !ruby/object:Gem::Dependency
68
- name: vidibus-secure
96
+ type: :runtime
69
97
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
98
+ name: httparty
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
71
100
  none: false
72
101
  requirements:
73
102
  - - ">="
@@ -76,12 +105,26 @@ dependencies:
76
105
  segments:
77
106
  - 0
78
107
  version: "0"
108
+ requirement: *id006
109
+ - !ruby/object:Gem::Dependency
79
110
  type: :runtime
80
- version_requirements: *id004
111
+ prerelease: false
112
+ name: json
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirement: *id007
81
123
  - !ruby/object:Gem::Dependency
82
- name: vidibus-validate_uri
124
+ type: :development
83
125
  prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
126
+ name: jeweler
127
+ version_requirements: &id008 !ruby/object:Gem::Requirement
85
128
  none: false
86
129
  requirements:
87
130
  - - ">="
@@ -90,12 +133,12 @@ dependencies:
90
133
  segments:
91
134
  - 0
92
135
  version: "0"
93
- type: :runtime
94
- version_requirements: *id005
136
+ requirement: *id008
95
137
  - !ruby/object:Gem::Dependency
96
- name: httparty
138
+ type: :development
97
139
  prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
140
+ name: rake
141
+ version_requirements: &id009 !ruby/object:Gem::Requirement
99
142
  none: false
100
143
  requirements:
101
144
  - - ">="
@@ -104,12 +147,30 @@ dependencies:
104
147
  segments:
105
148
  - 0
106
149
  version: "0"
107
- type: :runtime
108
- version_requirements: *id006
150
+ requirement: *id009
109
151
  - !ruby/object:Gem::Dependency
110
- name: json
152
+ type: :development
153
+ prerelease: false
154
+ name: rspec
155
+ version_requirements: &id010 !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ~>
159
+ - !ruby/object:Gem::Version
160
+ hash: 62196427
161
+ segments:
162
+ - 2
163
+ - 0
164
+ - 0
165
+ - beta
166
+ - 20
167
+ version: 2.0.0.beta.20
168
+ requirement: *id010
169
+ - !ruby/object:Gem::Dependency
170
+ type: :development
111
171
  prerelease: false
112
- requirement: &id007 !ruby/object:Gem::Requirement
172
+ name: rr
173
+ version_requirements: &id011 !ruby/object:Gem::Requirement
113
174
  none: false
114
175
  requirements:
115
176
  - - ">="
@@ -118,8 +179,35 @@ dependencies:
118
179
  segments:
119
180
  - 0
120
181
  version: "0"
121
- type: :runtime
122
- version_requirements: *id007
182
+ requirement: *id011
183
+ - !ruby/object:Gem::Dependency
184
+ type: :development
185
+ prerelease: false
186
+ name: relevance-rcov
187
+ version_requirements: &id012 !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ hash: 3
193
+ segments:
194
+ - 0
195
+ version: "0"
196
+ requirement: *id012
197
+ - !ruby/object:Gem::Dependency
198
+ type: :development
199
+ prerelease: false
200
+ name: webmock
201
+ version_requirements: &id013 !ruby/object:Gem::Requirement
202
+ none: false
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ hash: 3
207
+ segments:
208
+ - 0
209
+ version: "0"
210
+ requirement: *id013
123
211
  description: Description...
124
212
  email: andre@vidibus.com
125
213
  executables: []
@@ -132,7 +220,6 @@ extra_rdoc_files:
132
220
  files:
133
221
  - .bundle/config
134
222
  - .document
135
- - .gitignore
136
223
  - .rspec
137
224
  - Gemfile
138
225
  - Gemfile.lock
@@ -161,8 +248,8 @@ homepage: http://github.com/vidibus/vidibus-service
161
248
  licenses: []
162
249
 
163
250
  post_install_message:
164
- rdoc_options:
165
- - --charset=UTF-8
251
+ rdoc_options: []
252
+
166
253
  require_paths:
167
254
  - lib
168
255
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC