pebblebed 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pebblebed/config.rb +3 -2
- data/lib/pebblebed/sinatra.rb +6 -1
- data/lib/pebblebed/version.rb +1 -1
- data/spec/config_spec.rb +22 -22
- data/spec/connector_spec.rb +39 -6
- data/spec/generic_client_spec.rb +17 -11
- data/spec/http_spec.rb +18 -13
- data/spec/labels_spec.rb +35 -7
- data/spec/river_spec.rb +8 -3
- data/spec/river_subscription_spec.rb +14 -9
- data/spec/security/access_data_spec.rb +8 -8
- data/spec/security/client_spec.rb +2 -2
- data/spec/security/listener_spec.rb +1 -1
- data/spec/security/role_shema_spec.rb +8 -8
- data/spec/sinatra_spec.rb +39 -39
- data/spec/uid_spec.rb +127 -82
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45691ca27096676c8395d306b07f6df6e91c4809
|
4
|
+
data.tar.gz: 2db3172af3d0db352483ccc3ff19f1ac99295c62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d895b88598b93db048cf27460e8d718678cf8314f18dfc53faa8e1f5b92faf3025a6ab2fe0bea15c502d1da6bdb1d0bdb5d85e1ee755e2c071fded6c6153557b
|
7
|
+
data.tar.gz: e98b26afac3664573ee9f8f825192d0e8389cd28804a958dbfd3635498b8df8a77e6cb4d8f93a36c6a7836c3afc10ddf50d18e6f979c99d08142a842c95a4f89
|
data/lib/pebblebed/config.rb
CHANGED
@@ -94,8 +94,9 @@ module Pebblebed
|
|
94
94
|
[:base_uri, :base_url].each do |key|
|
95
95
|
return url_opts[key] if url_opts[key]
|
96
96
|
end
|
97
|
-
|
98
|
-
|
97
|
+
scheme = url_opts[:scheme] || 'http'
|
98
|
+
return "#{scheme}://#{url_opts[:host]}" if url_opts[:host]
|
99
|
+
base_uri || "#{scheme}://#{host}"
|
99
100
|
end
|
100
101
|
end
|
101
102
|
end
|
data/lib/pebblebed/sinatra.rb
CHANGED
@@ -33,7 +33,12 @@ module Sinatra
|
|
33
33
|
alias :checkpoint_session :current_session
|
34
34
|
|
35
35
|
def pebbles
|
36
|
-
@pebbles
|
36
|
+
return @pebbles if @pebbles
|
37
|
+
connector_options = {
|
38
|
+
:host => ::Pebblebed.host || request.host,
|
39
|
+
:scheme => request.scheme
|
40
|
+
}
|
41
|
+
@pebbles = ::Pebblebed::Connector.new(checkpoint_session, connector_options)
|
37
42
|
end
|
38
43
|
|
39
44
|
def current_identity_data
|
data/lib/pebblebed/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -11,20 +11,20 @@ describe Pebblebed do
|
|
11
11
|
service :checkpoint
|
12
12
|
end
|
13
13
|
|
14
|
-
Pebblebed.host.
|
15
|
-
Pebblebed.memcached.
|
16
|
-
Pebblebed.session_cookie.
|
17
|
-
Pebblebed::Connector.instance_methods.
|
14
|
+
expect(Pebblebed.host).to eq "example.org"
|
15
|
+
expect(Pebblebed.memcached).to eq "MemcachedClient"
|
16
|
+
expect(Pebblebed.session_cookie).to eq "my.session"
|
17
|
+
expect(Pebblebed::Connector.instance_methods).to include :checkpoint
|
18
18
|
end
|
19
19
|
|
20
20
|
it "raises an error when memcached is used but not configured" do
|
21
21
|
Pebblebed.memcached = nil
|
22
|
-
|
22
|
+
expect {Pebblebed.memcached}.to raise_error RuntimeError
|
23
23
|
end
|
24
24
|
|
25
25
|
it "has a default name of 'checkpoint.session' for the session cookie" do
|
26
26
|
Pebblebed.session_cookie = nil
|
27
|
-
Pebblebed.session_cookie.
|
27
|
+
expect(Pebblebed.session_cookie).to eq "checkpoint.session"
|
28
28
|
end
|
29
29
|
|
30
30
|
it "can calculate the root uri of any pebble" do
|
@@ -33,9 +33,9 @@ describe Pebblebed do
|
|
33
33
|
service :foobar, :version => 2
|
34
34
|
end
|
35
35
|
Pebblebed.host = "example.org"
|
36
|
-
Pebblebed.root_url_for(:checkpoint).to_s.
|
37
|
-
Pebblebed.root_url_for(:checkpoint, :host => 'checkpoint.dev').to_s.
|
38
|
-
Pebblebed.root_url_for(:foobar).to_s.
|
36
|
+
expect(Pebblebed.root_url_for(:checkpoint).to_s).to eq "http://example.org/api/checkpoint/v1/"
|
37
|
+
expect(Pebblebed.root_url_for(:checkpoint, :host => 'checkpoint.dev').to_s).to eq "http://checkpoint.dev/api/checkpoint/v1/"
|
38
|
+
expect(Pebblebed.root_url_for(:foobar).to_s).to eq "http://example.org/api/foobar/v2/"
|
39
39
|
end
|
40
40
|
|
41
41
|
it "allows the path of a pebble to be overridden" do
|
@@ -44,9 +44,9 @@ describe Pebblebed do
|
|
44
44
|
service :foobar, :version => 2
|
45
45
|
end
|
46
46
|
Pebblebed.host = "example.org"
|
47
|
-
Pebblebed.root_url_for(:checkpoint).to_s.
|
48
|
-
Pebblebed.root_url_for(:checkpoint, :host => 'checkpoint.dev').to_s.
|
49
|
-
Pebblebed.root_url_for(:foobar).to_s.
|
47
|
+
expect(Pebblebed.root_url_for(:checkpoint).to_s).to eq "http://example.org/my_api/my_checkpoint/v1/"
|
48
|
+
expect(Pebblebed.root_url_for(:checkpoint, :host => 'checkpoint.dev').to_s).to eq "http://checkpoint.dev/my_api/my_checkpoint/v1/"
|
49
|
+
expect(Pebblebed.root_url_for(:foobar).to_s).to eq "http://example.org/api/foobar/v2/"
|
50
50
|
end
|
51
51
|
|
52
52
|
it "allows the host of a pebble to be overridden" do
|
@@ -54,8 +54,8 @@ describe Pebblebed do
|
|
54
54
|
service :checkpoint, host: 'example.net'
|
55
55
|
end
|
56
56
|
Pebblebed.host = "example.org"
|
57
|
-
Pebblebed.root_url_for(:checkpoint).to_s.
|
58
|
-
Pebblebed.root_url_for(:checkpoint, :host => 'checkpoint.dev').to_s.
|
57
|
+
expect(Pebblebed.root_url_for(:checkpoint).to_s).to eq "http://example.net/api/checkpoint/v1/"
|
58
|
+
expect(Pebblebed.root_url_for(:checkpoint, :host => 'checkpoint.dev').to_s).to eq "http://checkpoint.dev/api/checkpoint/v1/"
|
59
59
|
end
|
60
60
|
|
61
61
|
it "works with pebbles that are exposed via https" do
|
@@ -64,9 +64,9 @@ describe Pebblebed do
|
|
64
64
|
service :foobar, :version => 2
|
65
65
|
end
|
66
66
|
Pebblebed.base_url = "https://example.org"
|
67
|
-
Pebblebed.root_url_for(:checkpoint).to_s.
|
68
|
-
Pebblebed.root_url_for(:checkpoint, :base_uri => 'https://checkpoint.dev').to_s.
|
69
|
-
Pebblebed.root_url_for(:foobar).to_s.
|
67
|
+
expect(Pebblebed.root_url_for(:checkpoint).to_s).to eq "https://example.org/api/checkpoint/v1/"
|
68
|
+
expect(Pebblebed.root_url_for(:checkpoint, :base_uri => 'https://checkpoint.dev').to_s).to eq "https://checkpoint.dev/api/checkpoint/v1/"
|
69
|
+
expect(Pebblebed.root_url_for(:foobar).to_s).to eq "https://example.org/api/foobar/v2/"
|
70
70
|
end
|
71
71
|
|
72
72
|
it "allows passed in parameters to take precedence" do
|
@@ -75,15 +75,15 @@ describe Pebblebed do
|
|
75
75
|
service :foobar, :version => 2
|
76
76
|
end
|
77
77
|
Pebblebed.base_url = "https://example.org"
|
78
|
-
Pebblebed.root_url_for(:checkpoint, :host => 'checkpoint.dev').to_s.
|
78
|
+
expect(Pebblebed.root_url_for(:checkpoint, :host => 'checkpoint.dev').to_s).to eq "http://checkpoint.dev/api/checkpoint/v1/"
|
79
79
|
end
|
80
80
|
|
81
81
|
it "raises an error if :host and :base_uri are both specified as parameters" do
|
82
82
|
Pebblebed.config do
|
83
83
|
service :checkpoint
|
84
84
|
end
|
85
|
-
|
86
|
-
|
85
|
+
expect {Pebblebed.root_url_for(:checkpoint, :base_uri => 'https://checkpoint.dev', :host => 'checkpoint.dev')}.to raise_error RuntimeError
|
86
|
+
expect {Pebblebed.root_url_for(:checkpoint, :base_url => 'https://checkpoint.dev', :host => 'checkpoint.dev')}.to raise_error RuntimeError
|
87
87
|
end
|
88
88
|
|
89
89
|
it "request_uri takes precedence over host" do
|
@@ -93,7 +93,7 @@ describe Pebblebed do
|
|
93
93
|
service :foobar, :version => 2
|
94
94
|
end
|
95
95
|
Pebblebed.base_url = "https://example.org"
|
96
|
-
Pebblebed.root_url_for(:checkpoint).to_s.
|
97
|
-
Pebblebed.root_url_for(:checkpoint, :base_uri => 'https://checkpoint.dev').to_s.
|
96
|
+
expect(Pebblebed.root_url_for(:checkpoint).to_s).to eq "https://example.org/api/checkpoint/v1/"
|
97
|
+
expect(Pebblebed.root_url_for(:checkpoint, :base_uri => 'https://checkpoint.dev').to_s).to eq "https://checkpoint.dev/api/checkpoint/v1/"
|
98
98
|
end
|
99
99
|
end
|
data/spec/connector_spec.rb
CHANGED
@@ -6,24 +6,57 @@ require 'pebblebed/clients/generic_client'
|
|
6
6
|
require 'pebblebed/clients/quorum_client'
|
7
7
|
|
8
8
|
describe "Pebblebed::Connector" do
|
9
|
+
|
10
|
+
Pebblebed.config do
|
11
|
+
service :foobar
|
12
|
+
end
|
13
|
+
|
9
14
|
it "can configure clients for any service" do
|
10
15
|
connector = Pebblebed::Connector.new("session_key")
|
11
16
|
client = connector['foobar']
|
12
|
-
client.class.name.
|
13
|
-
client.instance_variable_get(:@session_key).
|
14
|
-
client.instance_variable_get(:@root_url).to_s.
|
17
|
+
expect(client.class.name).to eq "Pebblebed::GenericClient"
|
18
|
+
expect(client.instance_variable_get(:@session_key)).to eq "session_key"
|
19
|
+
expect(client.instance_variable_get(:@root_url).to_s).to match(/api\/foobar/)
|
15
20
|
end
|
16
21
|
|
17
22
|
it "caches any given client" do
|
18
23
|
connector = Pebblebed::Connector.new("session_key")
|
19
|
-
connector['foobar'].
|
24
|
+
expect(connector['foobar']).to eq connector['foobar']
|
20
25
|
end
|
21
26
|
|
22
27
|
it "has key getter and setter" do
|
23
28
|
connector = Pebblebed::Connector.new("session_key")
|
24
|
-
connector.key.
|
29
|
+
expect(connector.key).to eq("session_key")
|
25
30
|
connector.key = "another_key"
|
26
|
-
connector.key.
|
31
|
+
expect(connector.key).to eq("another_key")
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'scheme' do
|
35
|
+
|
36
|
+
Pebblebed.config do
|
37
|
+
service :barbaz
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'works for http' do
|
41
|
+
connector_options = {
|
42
|
+
:host => 'example.org',
|
43
|
+
:scheme => 'http'
|
44
|
+
}
|
45
|
+
connector = ::Pebblebed::Connector.new('session_key', connector_options)
|
46
|
+
client = connector['barbaz']
|
47
|
+
expect(client.instance_variable_get(:@root_url).to_s).to eq 'http://example.org/api/barbaz/v1/'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'works for https' do
|
51
|
+
connector_options = {
|
52
|
+
:host => 'example.org',
|
53
|
+
:scheme => 'https'
|
54
|
+
}
|
55
|
+
connector = ::Pebblebed::Connector.new('session_key', connector_options)
|
56
|
+
client = connector['barbaz']
|
57
|
+
expect(client.instance_variable_get(:@root_url).to_s).to eq 'https://example.org/api/barbaz/v1/'
|
58
|
+
end
|
59
|
+
|
27
60
|
end
|
28
61
|
|
29
62
|
end
|
data/spec/generic_client_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'pebblebed/config'
|
2
3
|
require 'pebblebed/clients/abstract_client'
|
3
4
|
require 'pebblebed/clients/generic_client'
|
4
5
|
|
@@ -8,39 +9,44 @@ module Pebblebed
|
|
8
9
|
end
|
9
10
|
|
10
11
|
describe Pebblebed::GenericClient do
|
12
|
+
|
13
|
+
Pebblebed.config do
|
14
|
+
memcached "MemcachedClient"
|
15
|
+
end
|
16
|
+
|
11
17
|
it "always forwards the session key" do
|
12
18
|
client = Pebblebed::GenericClient.new("session_key", "http://example.org/")
|
13
|
-
client.service_params({})['session'].
|
19
|
+
expect(client.service_params({})['session']).to eq "session_key"
|
14
20
|
end
|
15
21
|
|
16
22
|
it "always converts urls to URI-objects" do
|
17
23
|
client = Pebblebed::GenericClient.new("session_key", "http://example.org/")
|
18
|
-
client.instance_variable_get(:@root_url).class.name.
|
24
|
+
expect(client.instance_variable_get(:@root_url).class.name).to eq ("URI::HTTP")
|
19
25
|
end
|
20
26
|
|
21
27
|
it "knows how to generate a service specific url" do
|
22
28
|
client = Pebblebed::GenericClient.new("session_key", "http://example.org/")
|
23
|
-
client.service_url("/test").to_s.
|
24
|
-
client.service_url("").to_s.
|
25
|
-
client.service_url("/test", :foo => 'bar').to_s.
|
29
|
+
expect(client.service_url("/test").to_s).to eq "http://example.org/test"
|
30
|
+
expect(client.service_url("").to_s).to eq "http://example.org"
|
31
|
+
expect(client.service_url("/test", :foo => 'bar').to_s).to eq "http://example.org/test?foo=bar"
|
26
32
|
end
|
27
33
|
|
28
34
|
it "wraps JSON-results in a deep struct" do
|
29
35
|
curl_result = DeepStruct.wrap({status:200, body:'{"hello":"world"}'})
|
30
|
-
Pebblebed::Http.
|
36
|
+
allow(Pebblebed::Http).to receive(:get).and_return(curl_result)
|
31
37
|
client = Pebblebed::GenericClient.new("session_key", "http://example.org/")
|
32
38
|
result = client.get "/"
|
33
|
-
result.class.name.
|
34
|
-
result.hello.
|
39
|
+
expect(result.class.name).to eq "DeepStruct::HashWrapper"
|
40
|
+
expect(result.hello).to eq "world"
|
35
41
|
end
|
36
42
|
|
37
43
|
it "does not wrap non-json results" do
|
38
44
|
curl_result = DeepStruct.wrap({status:200, body:'Ok'})
|
39
|
-
Pebblebed::Http.
|
45
|
+
allow(Pebblebed::Http).to receive(:get).and_return(curl_result)
|
40
46
|
client = Pebblebed::GenericClient.new("session_key", "http://example.org/")
|
41
47
|
result = client.get "/"
|
42
|
-
result.class.name.
|
43
|
-
result.
|
48
|
+
expect(result.class.name).to eq "String"
|
49
|
+
expect(result).to eq "Ok"
|
44
50
|
end
|
45
51
|
|
46
52
|
end
|
data/spec/http_spec.rb
CHANGED
@@ -3,10 +3,15 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require 'yajl/json_gem'
|
5
5
|
require 'pebblebed/http'
|
6
|
+
require 'pebblebed/config'
|
6
7
|
require 'deepstruct'
|
7
8
|
|
8
9
|
describe Pebblebed::Http do
|
9
10
|
|
11
|
+
Pebblebed.config do
|
12
|
+
memcached "MemcachedClient"
|
13
|
+
end
|
14
|
+
|
10
15
|
def mock_pebble
|
11
16
|
@mp ||= MockPebble.new
|
12
17
|
end
|
@@ -27,43 +32,43 @@ describe Pebblebed::Http do
|
|
27
32
|
end
|
28
33
|
|
29
34
|
it "knows how to pack params into a http query string" do
|
30
|
-
Pebblebed::Http.send(:url_with_params, URI("/dingo/"), {a:1}).
|
35
|
+
expect(Pebblebed::Http.send(:url_with_params, URI("/dingo/"), {a:1})).to eq "/dingo/?a=1"
|
31
36
|
end
|
32
37
|
|
33
38
|
it "knows how to combine url and parmas with results of pathbuilder" do
|
34
39
|
url, params = Pebblebed::Http.send(:url_and_params_from_args, URI("http://example.org/api"), {a:1}) do
|
35
40
|
foo.bar(:b => 2)
|
36
41
|
end
|
37
|
-
params.
|
38
|
-
url.to_s.
|
42
|
+
expect(params).to eq(:a => 1, :b => 2)
|
43
|
+
expect(url.to_s).to eq "http://example.org/api/foo/bar"
|
39
44
|
end
|
40
45
|
|
41
46
|
it "handles urls as strings" do
|
42
47
|
url, params = Pebblebed::Http.send(:url_and_params_from_args, "http://example.org/api", {a:1}) do
|
43
48
|
foo.bar(:b => 2)
|
44
49
|
end
|
45
|
-
params.
|
46
|
-
url.to_s.
|
50
|
+
expect(params).to eq(:a => 1, :b => 2)
|
51
|
+
expect(url.to_s).to eq "http://example.org/api/foo/bar"
|
47
52
|
end
|
48
53
|
|
49
54
|
it "raises an HttpNotFoundError if there is a 404 error" do
|
50
|
-
|
55
|
+
expect { Pebblebed::Http.send(:handle_http_errors, DeepStruct.wrap(status: 404, url: "/foobar", body: "Not found")) }.to raise_error Pebblebed::HttpNotFoundError
|
51
56
|
end
|
52
57
|
|
53
58
|
it "includes the url of the failed resource in the error message" do
|
54
|
-
|
59
|
+
expect { Pebblebed::Http.send(:handle_http_errors, DeepStruct.wrap(status: 404, url: "/nosuchresource", body: "Not found")) }.to raise_error Pebblebed::HttpNotFoundError, /\/nosuchresource/
|
55
60
|
end
|
56
61
|
|
57
62
|
it "raises an HttpError if there is any other http-error" do
|
58
|
-
|
63
|
+
expect { Pebblebed::Http.send(:handle_http_errors, DeepStruct.wrap(status: 400, url: "/foobar", body: "Oh noes")) }.to raise_error Pebblebed::HttpError
|
59
64
|
end
|
60
65
|
|
61
66
|
it "encodes posts and puts as json if the params is a hash" do
|
62
67
|
['post', 'put'].each do |method|
|
63
68
|
response = Pebblebed::Http.send(method.to_sym, pebble_url, {hello:'world'})
|
64
69
|
result = JSON.parse(response.body)
|
65
|
-
result["CONTENT_TYPE"].
|
66
|
-
JSON.parse(result["BODY"])['hello'].
|
70
|
+
expect(result["CONTENT_TYPE"]).to match(%r{^application/json\b}i)
|
71
|
+
expect(JSON.parse(result["BODY"])['hello']).to eq 'world'
|
67
72
|
end
|
68
73
|
end
|
69
74
|
|
@@ -71,15 +76,15 @@ describe Pebblebed::Http do
|
|
71
76
|
['post', 'put'].each do |method|
|
72
77
|
response = Pebblebed::Http.send(method.to_sym, pebble_url, "Hello world")
|
73
78
|
result = JSON.parse(response.body)
|
74
|
-
result["CONTENT_TYPE"].
|
75
|
-
result["BODY"].
|
79
|
+
expect(result["CONTENT_TYPE"]).to match(%r{^text/plain\b}i)
|
80
|
+
expect(result["BODY"]).to eq "Hello world"
|
76
81
|
end
|
77
82
|
end
|
78
83
|
|
79
84
|
it "encodes gets as url params" do
|
80
85
|
response = Pebblebed::Http.get(pebble_url, {hello: 'world'})
|
81
86
|
result = JSON.parse(response.body)
|
82
|
-
result["QUERY_STRING"].
|
87
|
+
expect(result["QUERY_STRING"]).to eq "hello=world"
|
83
88
|
end
|
84
89
|
|
85
90
|
end
|
data/spec/labels_spec.rb
CHANGED
@@ -5,29 +5,57 @@ describe Pebblebed::Labels do
|
|
5
5
|
|
6
6
|
describe "default labels" do
|
7
7
|
subject { Pebblebed::Labels.new('a.b.c') }
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
describe '#expanded' do
|
10
|
+
subject { super().expanded }
|
11
|
+
it { is_expected.to eq('label_0' => "a", 'label_1' => "b", 'label_2' => "c") }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#wildcard?' do
|
15
|
+
subject { super().wildcard? }
|
16
|
+
it { is_expected.to eq(false) }
|
17
|
+
end
|
10
18
|
end
|
11
19
|
|
12
20
|
describe "with a stop label" do
|
13
21
|
subject { Pebblebed::Labels.new('a.b.c', :stop => nil) }
|
14
|
-
|
22
|
+
|
23
|
+
describe '#expanded' do
|
24
|
+
subject { super().expanded }
|
25
|
+
it { is_expected.to eq('label_0' => "a", 'label_1' => "b", 'label_2' => "c", 'label_3' => nil) }
|
26
|
+
end
|
15
27
|
end
|
16
28
|
|
17
29
|
describe "customized labels" do
|
18
30
|
subject { Pebblebed::Labels.new('p.r.q', :prefix => 'dot', :suffix => '', :stop => '<END>') }
|
19
|
-
|
31
|
+
|
32
|
+
describe '#expanded' do
|
33
|
+
subject { super().expanded }
|
34
|
+
it { is_expected.to eq('dot_0_' => 'p', 'dot_1_' => 'r', 'dot_2_' => 'q', 'dot_3_' => '<END>') }
|
35
|
+
end
|
20
36
|
end
|
21
37
|
|
22
38
|
describe "next label" do
|
23
39
|
subject { Pebblebed::Labels.new('a.b.c', :prefix => 'thing') }
|
24
|
-
|
40
|
+
|
41
|
+
describe '#next' do
|
42
|
+
subject { super().next }
|
43
|
+
it { is_expected.to eq('thing_3') }
|
44
|
+
end
|
25
45
|
end
|
26
46
|
|
27
47
|
describe "with wildcard *" do
|
28
48
|
subject { Pebblebed::Labels.new('a.b.c.*') }
|
29
|
-
|
30
|
-
|
49
|
+
|
50
|
+
describe '#expanded' do
|
51
|
+
subject { super().expanded }
|
52
|
+
it { is_expected.to eq('label_0' => "a", 'label_1' => "b", 'label_2' => "c") }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#wildcard?' do
|
56
|
+
subject { super().wildcard? }
|
57
|
+
it { is_expected.to eq(true) }
|
58
|
+
end
|
31
59
|
end
|
32
60
|
|
33
61
|
end
|
data/spec/river_spec.rb
CHANGED
@@ -1,22 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'pebblebed/river'
|
3
3
|
require 'pebblebed/uid'
|
4
|
+
require 'pebblebed/config'
|
4
5
|
|
5
6
|
describe Pebblebed::River do
|
6
7
|
|
7
8
|
describe "routing keys" do
|
8
9
|
|
10
|
+
Pebblebed.config do
|
11
|
+
memcached 'MemcachedClient'
|
12
|
+
end
|
13
|
+
|
9
14
|
specify do
|
10
15
|
options = {:event => 'created', :uid => 'post.awesome.event:feeds.bagera.whatevs$123'}
|
11
|
-
Pebblebed::River.route(options).
|
16
|
+
expect(Pebblebed::River.route(options)).to eq('created._.post.awesome.event._.feeds.bagera.whatevs')
|
12
17
|
end
|
13
18
|
|
14
19
|
specify "event is required" do
|
15
|
-
|
20
|
+
expect{ Pebblebed::River.route(:uid => 'whatevs') }.to raise_error ArgumentError
|
16
21
|
end
|
17
22
|
|
18
23
|
specify "uid is required" do
|
19
|
-
|
24
|
+
expect{ Pebblebed::River.route(:event => 'whatevs') }.to raise_error ArgumentError
|
20
25
|
end
|
21
26
|
|
22
27
|
end
|
@@ -1,30 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'pebblebed/config'
|
2
3
|
require 'pebblebed/river/subscription'
|
3
4
|
|
4
5
|
describe Pebblebed::River::Subscription do
|
5
6
|
|
7
|
+
Pebblebed.config do
|
8
|
+
memcached 'MemcachedClient'
|
9
|
+
end
|
10
|
+
|
6
11
|
Subscription = Pebblebed::River::Subscription
|
7
12
|
|
8
13
|
specify 'simple, direct match' do
|
9
14
|
options = {:event => 'create', :klass => 'post.event', :path => 'feed.bagera'}
|
10
15
|
subscription = Subscription.new(options)
|
11
|
-
subscription.queries.
|
16
|
+
expect(subscription.queries).to eq(['create._.post.event._.feed.bagera'])
|
12
17
|
end
|
13
18
|
|
14
19
|
specify 'simple wildcard match' do
|
15
20
|
options = {:event => '*.create', :klass => 'post.*', :path => '*.bagera.*'}
|
16
|
-
Subscription.new(options).queries.
|
21
|
+
expect(Subscription.new(options).queries).to eq(['*.create._.post.*._.*.bagera.*'])
|
17
22
|
end
|
18
23
|
|
19
24
|
describe "anything matchers" do
|
20
25
|
|
21
26
|
specify 'match anything (duh)' do
|
22
27
|
options = {:event => '**', :klass => '**', :path => '**'}
|
23
|
-
Subscription.new(options).queries.
|
28
|
+
expect(Subscription.new(options).queries).to eq(['#._.#._.#'])
|
24
29
|
end
|
25
30
|
|
26
31
|
specify 'match anything if not specified' do
|
27
|
-
Subscription.new.queries.
|
32
|
+
expect(Subscription.new.queries).to eq(['#._.#._.#'])
|
28
33
|
end
|
29
34
|
|
30
35
|
end
|
@@ -32,18 +37,18 @@ describe Pebblebed::River::Subscription do
|
|
32
37
|
it 'handles "or" queries' do
|
33
38
|
options = {:event => 'create|delete', :klass => 'post', :path => 'bagera|bandwagon'}
|
34
39
|
expected = ['create._.post._.bagera', 'delete._.post._.bagera', 'create._.post._.bandwagon', 'delete._.post._.bandwagon'].sort
|
35
|
-
Subscription.new(options).queries.sort.
|
40
|
+
expect(Subscription.new(options).queries.sort).to eq(expected)
|
36
41
|
end
|
37
42
|
|
38
43
|
describe "optional paths" do
|
39
|
-
it { Subscription.new.pathify('a.b').
|
40
|
-
it { Subscription.new.pathify('a.^b.c').
|
44
|
+
it { expect(Subscription.new.pathify('a.b')).to eq(['a.b']) }
|
45
|
+
it { expect(Subscription.new.pathify('a.^b.c')).to eq(%w(a a.b a.b.c)) }
|
41
46
|
end
|
42
47
|
|
43
48
|
it "handles optional queries" do
|
44
49
|
options = {:event => 'create', :klass => 'post', :path => 'feeds.bagera.^fb.concerts'}
|
45
50
|
expected = ['create._.post._.feeds.bagera', 'create._.post._.feeds.bagera.fb', 'create._.post._.feeds.bagera.fb.concerts'].sort
|
46
|
-
Subscription.new(options).queries.sort.
|
51
|
+
expect(Subscription.new(options).queries.sort).to eq(expected)
|
47
52
|
end
|
48
53
|
|
49
54
|
it "combines all kinds of weird stuff" do
|
@@ -56,7 +61,7 @@ describe Pebblebed::River::Subscription do
|
|
56
61
|
'create._.post._.x.y',
|
57
62
|
'create._.post._.x.y.z',
|
58
63
|
].sort
|
59
|
-
Subscription.new(options).queries.sort.
|
64
|
+
expect(Subscription.new(options).queries.sort).to eq(expected)
|
60
65
|
end
|
61
66
|
|
62
67
|
end
|
@@ -11,15 +11,15 @@ describe Pebblebed::Security::AccessData do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "can calculate a pristine path" do
|
14
|
-
Pebblebed::Security::AccessData.pristine_path("a.b.c|d").
|
15
|
-
Pebblebed::Security::AccessData.pristine_path("a.b").
|
14
|
+
expect(Pebblebed::Security::AccessData.pristine_path("a.b.c|d")).to eq "a.b"
|
15
|
+
expect(Pebblebed::Security::AccessData.pristine_path("a.b")).to eq "a.b"
|
16
16
|
end
|
17
17
|
|
18
18
|
it "can calculate relevant paths" do
|
19
|
-
access_data.relevant_subtrees('a.b').sort.
|
20
|
-
access_data.relevant_subtrees('a.b.c').sort.
|
21
|
-
access_data.relevant_subtrees('a.c.e').sort.
|
22
|
-
access_data.relevant_subtrees('a.*').sort.
|
19
|
+
expect(access_data.relevant_subtrees('a.b').sort).to eq ['a.b', 'a.b.c.d.e']
|
20
|
+
expect(access_data.relevant_subtrees('a.b.c').sort).to eq ['a.b', 'a.b.c.d.e']
|
21
|
+
expect(access_data.relevant_subtrees('a.c.e').sort).to eq ['a.c.e.f']
|
22
|
+
expect(access_data.relevant_subtrees('a.*').sort).to eq ['a.b', 'a.b.c.d.e', 'a.c.d', 'a.c.e.f']
|
23
23
|
end
|
24
24
|
|
25
25
|
it "can parse a checkpoint record" do
|
@@ -34,7 +34,7 @@ describe Pebblebed::Security::AccessData do
|
|
34
34
|
]
|
35
35
|
}
|
36
36
|
ad = Pebblebed::Security::AccessData.new(record)
|
37
|
-
ad.subtrees.sort.
|
38
|
-
ad.group_ids.sort.
|
37
|
+
expect(ad.subtrees.sort).to eq ['a.b.c', 'a.c.d.c']
|
38
|
+
expect(ad.group_ids.sort).to eq [1,2]
|
39
39
|
end
|
40
40
|
end
|
@@ -22,8 +22,8 @@ describe Pebblebed::Security::Client do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "can fetch access_data" do
|
25
|
-
client.
|
25
|
+
allow(client).to receive(:fetch_membership_data_for).and_return(sample_memberships_record)
|
26
26
|
ad = client.access_data_for(1)
|
27
|
-
ad.subtrees.sort.
|
27
|
+
expect(ad.subtrees.sort).to eq ['a.b.c', 'a.c.d.c']
|
28
28
|
end
|
29
29
|
end
|
@@ -64,17 +64,17 @@ describe Pebblebed::Security::RoleSchema do
|
|
64
64
|
}
|
65
65
|
|
66
66
|
it "has connector and identity attributes" do
|
67
|
-
schema.connector.
|
68
|
-
schema.identity.
|
67
|
+
expect(schema.connector).to eq connector
|
68
|
+
expect(schema.identity).to eq guest
|
69
69
|
end
|
70
70
|
|
71
71
|
it "has the correct roles defined" do
|
72
|
-
CustomRoleSchema.roles.
|
72
|
+
expect(CustomRoleSchema.roles).to eq([{:capabilities=>[], :requirements=>[], :name=>:guest, :role_rank=>0, :upgrades=>{:kudo=>[:logged_in], :comment=>[:logged_in, :verified_mobile]}}, {:capabilities=>[:kudo], :requirements=>[:logged_in], :name=>:identified, :role_rank=>1}, {:capabilities=>[:comment], :requirements=>[:logged_in, :verified_mobile], :name=>:contributor, :role_rank=>2}])
|
73
73
|
end
|
74
74
|
|
75
75
|
it "has an answer to requirements for a role" do
|
76
|
-
CustomRoleSchema.requirements_for_role(:identified).
|
77
|
-
CustomRoleSchema.requirements_for_role(:contributor).
|
76
|
+
expect(CustomRoleSchema.requirements_for_role(:identified)).to eq([:logged_in])
|
77
|
+
expect(CustomRoleSchema.requirements_for_role(:contributor)).to eq([:logged_in, :verified_mobile])
|
78
78
|
end
|
79
79
|
|
80
80
|
it "gives a exception when the role is not found" do
|
@@ -92,7 +92,7 @@ describe Pebblebed::Security::RoleSchema do
|
|
92
92
|
}
|
93
93
|
|
94
94
|
it "returns the guest role" do
|
95
|
-
schema.role.
|
95
|
+
expect(schema.role).to eq({:current=>:guest, :capabilities=>[], :upgrades=>{:kudo=>[:logged_in], :comment=>[:logged_in, :verified_mobile]}})
|
96
96
|
end
|
97
97
|
|
98
98
|
end
|
@@ -106,7 +106,7 @@ describe Pebblebed::Security::RoleSchema do
|
|
106
106
|
}
|
107
107
|
|
108
108
|
it "returns the idenitified role with an upgrade for :verified_mobile only" do
|
109
|
-
schema.role.
|
109
|
+
expect(schema.role).to eq({:current=>:identified, :capabilities=>[:kudo], :upgrades=>{:comment=>[:verified_mobile]}})
|
110
110
|
end
|
111
111
|
|
112
112
|
end
|
@@ -118,7 +118,7 @@ describe Pebblebed::Security::RoleSchema do
|
|
118
118
|
}
|
119
119
|
|
120
120
|
it "returns the contributor role" do
|
121
|
-
schema.role.
|
121
|
+
expect(schema.role).to eq({:current=>:contributor, :capabilities=>[:kudo, :comment], :upgrades=>{}})
|
122
122
|
end
|
123
123
|
|
124
124
|
end
|
data/spec/sinatra_spec.rb
CHANGED
@@ -70,22 +70,22 @@ describe Sinatra::Pebblebed do
|
|
70
70
|
|
71
71
|
specify "can see public endpoint" do
|
72
72
|
get '/public'
|
73
|
-
last_response.body.
|
73
|
+
expect(last_response.body).to eq('You are a guest here')
|
74
74
|
end
|
75
75
|
|
76
76
|
it "can assign a provisional identity" do
|
77
77
|
get '/public', :provisional => 'yes'
|
78
|
-
last_response.status.
|
78
|
+
expect(last_response.status).to eq(302)
|
79
79
|
end
|
80
80
|
|
81
81
|
specify "cannot see private endpoints" do
|
82
82
|
get '/private'
|
83
|
-
last_response.status.
|
83
|
+
expect(last_response.status).to eq(403)
|
84
84
|
end
|
85
85
|
|
86
86
|
it "cannot see root endpoints" do
|
87
87
|
get '/root'
|
88
|
-
last_response.status.
|
88
|
+
expect(last_response.status).to eq(403)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -94,17 +94,17 @@ describe Sinatra::Pebblebed do
|
|
94
94
|
|
95
95
|
specify "can see public endpoint" do
|
96
96
|
get '/public'
|
97
|
-
last_response.body.
|
97
|
+
expect(last_response.body).to eq('You are a guest here')
|
98
98
|
end
|
99
99
|
|
100
100
|
specify "can see private endpoints" do
|
101
101
|
get '/private'
|
102
|
-
last_response.body.
|
102
|
+
expect(last_response.body).to eq('You are logged in')
|
103
103
|
end
|
104
104
|
|
105
105
|
it "cannot see root endpoints" do
|
106
106
|
get '/root'
|
107
|
-
last_response.status.
|
107
|
+
expect(last_response.status).to eq(403)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -113,17 +113,17 @@ describe Sinatra::Pebblebed do
|
|
113
113
|
|
114
114
|
specify "can see public endpoint" do
|
115
115
|
get '/public'
|
116
|
-
last_response.body.
|
116
|
+
expect(last_response.body).to eq('You are a guest here')
|
117
117
|
end
|
118
118
|
|
119
119
|
specify "can see private endpoints" do
|
120
120
|
get '/private'
|
121
|
-
last_response.body.
|
121
|
+
expect(last_response.body).to eq('You are logged in')
|
122
122
|
end
|
123
123
|
|
124
124
|
it "cannot see root endpoints" do
|
125
125
|
get '/root'
|
126
|
-
last_response.body.
|
126
|
+
expect(last_response.body).to eq('You are most powerful')
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -136,34 +136,34 @@ describe Sinatra::Pebblebed do
|
|
136
136
|
specify "not allowed" do
|
137
137
|
guest!
|
138
138
|
get '/group'
|
139
|
-
last_response.status.
|
139
|
+
expect(last_response.status).to eq(403)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
context "as a god" do
|
143
143
|
specify "allowed without policy check" do
|
144
144
|
god!(:session => random_session)
|
145
145
|
get '/group'
|
146
|
-
last_response.body.
|
146
|
+
expect(last_response.body).to eq("You are granted access to this content")
|
147
147
|
end
|
148
148
|
end
|
149
149
|
context "as user without grants" do
|
150
150
|
specify "is disallowed" do
|
151
151
|
user!
|
152
|
-
checkpoint.
|
153
|
-
checkpoint.
|
152
|
+
expect(checkpoint).to receive(:get).with("/identities/me").and_return(DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false}))
|
153
|
+
expect(checkpoint).to receive(:get).with("/identities/1/access_to/testrealm.specialgroup.123").and_return(DeepStruct.wrap(:access => {:granted => false}))
|
154
154
|
Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
|
155
155
|
get '/group'
|
156
|
-
last_response.status.
|
156
|
+
expect(last_response.status).to eq(403)
|
157
157
|
end
|
158
158
|
end
|
159
159
|
context "as user with grants" do
|
160
160
|
specify "is allowed" do
|
161
161
|
user!
|
162
|
-
checkpoint.
|
163
|
-
checkpoint.
|
162
|
+
expect(checkpoint).to receive(:get).with("/identities/me").and_return(DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false}))
|
163
|
+
expect(checkpoint).to receive(:get).with("/identities/1/access_to/testrealm.specialgroup.123").and_return(DeepStruct.wrap(:access => {:granted => true}))
|
164
164
|
Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
|
165
165
|
get '/group'
|
166
|
-
last_response.body.
|
166
|
+
expect(last_response.body).to eq("You are granted access to this content")
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end
|
@@ -177,64 +177,64 @@ describe Sinatra::Pebblebed do
|
|
177
177
|
specify "not allowed" do
|
178
178
|
guest!
|
179
179
|
post '/create/post.foo:testrealm'
|
180
|
-
last_response.status.
|
180
|
+
expect(last_response.status).to eq(403)
|
181
181
|
end
|
182
182
|
end
|
183
183
|
context "as a god" do
|
184
184
|
specify "allowed without callbacks" do
|
185
185
|
god!(:session => random_session)
|
186
186
|
post '/create/post.foo:testrealm'
|
187
|
-
last_response.body.
|
187
|
+
expect(last_response.body).to eq("You are creative")
|
188
188
|
end
|
189
189
|
end
|
190
190
|
context "as user without permissions" do
|
191
191
|
specify "is disallowed" do
|
192
192
|
user!
|
193
|
-
checkpoint.
|
194
|
-
checkpoint.
|
193
|
+
expect(checkpoint).to receive(:get).with("/identities/me").and_return(DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false}))
|
194
|
+
expect(checkpoint).to receive(:post).with("/callbacks/allowed/create/post.foo:testrealm").and_return(DeepStruct.wrap(:allowed => false, :reason => "You are not worthy!"))
|
195
195
|
Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
|
196
196
|
post '/create/post.foo:testrealm'
|
197
|
-
last_response.status.
|
198
|
-
last_response.body.
|
197
|
+
expect(last_response.status).to eq(403)
|
198
|
+
expect(last_response.body).to eq(":create denied for post.foo:testrealm : You are not worthy!")
|
199
199
|
end
|
200
200
|
end
|
201
201
|
context "as user with permissions" do
|
202
202
|
specify "is allowed" do
|
203
203
|
user!
|
204
|
-
checkpoint.
|
205
|
-
checkpoint.
|
204
|
+
expect(checkpoint).to receive(:get).with("/identities/me").and_return(DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false}))
|
205
|
+
expect(checkpoint).to receive(:post).with("/callbacks/allowed/create/post.foo:testrealm").and_return(DeepStruct.wrap(:allowed => true))
|
206
206
|
Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
|
207
207
|
post '/create/post.foo:testrealm'
|
208
|
-
last_response.body.
|
208
|
+
expect(last_response.body).to eq("You are creative")
|
209
209
|
end
|
210
210
|
context "with options[:default] => false" do
|
211
211
|
specify "is disallowed" do
|
212
212
|
user!
|
213
|
-
checkpoint.
|
214
|
-
checkpoint.
|
213
|
+
expect(checkpoint).to receive(:get).with("/identities/me").and_return(DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false}))
|
214
|
+
expect(checkpoint).to receive(:post).with("/callbacks/allowed/create/post.foo:testrealm").and_return(DeepStruct.wrap(:allowed => "default"))
|
215
215
|
Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
|
216
216
|
post '/create2/post.foo:testrealm'
|
217
|
-
last_response.status.
|
217
|
+
expect(last_response.status).to eq(403)
|
218
218
|
end
|
219
219
|
end
|
220
220
|
context "with no options given and allowed = default" do
|
221
221
|
specify "is disallowed" do
|
222
222
|
user!
|
223
|
-
checkpoint.
|
224
|
-
checkpoint.
|
223
|
+
expect(checkpoint).to receive(:get).with("/identities/me").and_return(DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false}))
|
224
|
+
expect(checkpoint).to receive(:post).with("/callbacks/allowed/create/post.foo:testrealm").and_return(DeepStruct.wrap(:allowed => "default"))
|
225
225
|
Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
|
226
226
|
post '/create/post.foo:testrealm'
|
227
|
-
last_response.status.
|
227
|
+
expect(last_response.status).to eq(403)
|
228
228
|
end
|
229
229
|
end
|
230
230
|
context "with options[:default] => true" do
|
231
231
|
specify "is allowed" do
|
232
232
|
user!
|
233
|
-
checkpoint.
|
234
|
-
checkpoint.
|
233
|
+
expect(checkpoint).to receive(:get).with("/identities/me").and_return(DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false}))
|
234
|
+
expect(checkpoint).to receive(:post).with("/callbacks/allowed/create/post.foo:testrealm").and_return(DeepStruct.wrap(:allowed => "default"))
|
235
235
|
Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
|
236
236
|
post '/create3/post.foo:testrealm'
|
237
|
-
last_response.body.
|
237
|
+
expect(last_response.body).to eq("You are creative")
|
238
238
|
end
|
239
239
|
end
|
240
240
|
end
|
@@ -247,14 +247,14 @@ describe Sinatra::Pebblebed do
|
|
247
247
|
let(:checkpoint) { Pebblebed::Connector.new.checkpoint }
|
248
248
|
|
249
249
|
it "is not turned on by default" do
|
250
|
-
checkpoint.
|
250
|
+
expect(checkpoint).to receive(:get).twice
|
251
251
|
get '/private'
|
252
252
|
get '/private'
|
253
253
|
end
|
254
254
|
|
255
255
|
it "can be turned on" do
|
256
256
|
app.set :cache_current_identity, true
|
257
|
-
checkpoint.
|
257
|
+
expect(checkpoint).to receive(:get).once
|
258
258
|
get '/private'
|
259
259
|
get '/private'
|
260
260
|
end
|
@@ -264,7 +264,7 @@ describe Sinatra::Pebblebed do
|
|
264
264
|
|
265
265
|
it "is disabled" do
|
266
266
|
app.set :cache_current_identity, true
|
267
|
-
checkpoint.
|
267
|
+
expect(checkpoint).to receive(:get).twice
|
268
268
|
get '/private'
|
269
269
|
get '/private'
|
270
270
|
end
|
data/spec/uid_spec.rb
CHANGED
@@ -6,67 +6,112 @@ describe Pebblebed::Uid do
|
|
6
6
|
context "a full uid" do
|
7
7
|
subject { Pebblebed::Uid.new("klass:path$oid") }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
describe '#klass' do
|
10
|
+
subject { super().klass }
|
11
|
+
it { is_expected.to eq "klass" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#path' do
|
15
|
+
subject { super().path }
|
16
|
+
it { is_expected.to eq "path" }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#oid' do
|
20
|
+
subject { super().oid }
|
21
|
+
it { is_expected.to eq "oid" }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#to_s' do
|
25
|
+
subject { super().to_s }
|
26
|
+
it { is_expected.to eq "klass:path$oid" }
|
27
|
+
end
|
13
28
|
end
|
14
29
|
|
15
30
|
context "without oid" do
|
16
31
|
subject { Pebblebed::Uid.new("klass:path") }
|
17
32
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
33
|
+
describe '#klass' do
|
34
|
+
subject { super().klass }
|
35
|
+
it { is_expected.to eq "klass" }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#path' do
|
39
|
+
subject { super().path }
|
40
|
+
it { is_expected.to eq "path" }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#oid' do
|
44
|
+
subject { super().oid }
|
45
|
+
it { is_expected.to be_nil }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#to_s' do
|
49
|
+
subject { super().to_s }
|
50
|
+
it { is_expected.to eq "klass:path" }
|
51
|
+
end
|
22
52
|
end
|
23
53
|
|
24
54
|
context "without path" do
|
25
55
|
subject { Pebblebed::Uid.new("klass:$oid") }
|
26
56
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
57
|
+
describe '#klass' do
|
58
|
+
subject { super().klass }
|
59
|
+
it { is_expected.to eq "klass" }
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#path' do
|
63
|
+
subject { super().path }
|
64
|
+
it { is_expected.to be_nil }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#oid' do
|
68
|
+
subject { super().oid }
|
69
|
+
it { is_expected.to eq "oid" }
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#to_s' do
|
73
|
+
subject { super().to_s }
|
74
|
+
it { is_expected.to eq "klass:$oid" }
|
75
|
+
end
|
31
76
|
end
|
32
77
|
end
|
33
78
|
|
34
79
|
it "can be created with a string" do
|
35
80
|
uid = Pebblebed::Uid.new "klass:some.path$oid"
|
36
|
-
uid.to_s.
|
81
|
+
expect(uid.to_s).to eq "klass:some.path$oid"
|
37
82
|
end
|
38
83
|
|
39
84
|
it "can be created using parameters" do
|
40
85
|
uid = Pebblebed::Uid.new :klass => 'klass', :path => 'some.path', :oid => 'oid'
|
41
|
-
uid.to_s.
|
86
|
+
expect(uid.to_s).to eq "klass:some.path$oid"
|
42
87
|
end
|
43
88
|
|
44
89
|
it "raises an error if parameter is neither string or hash" do
|
45
|
-
|
90
|
+
expect {Pebblebed::Uid.new([])}.to raise_exception
|
46
91
|
end
|
47
92
|
|
48
93
|
it "raises an exception when you try to create an invalid uid" do
|
49
|
-
|
94
|
+
expect { Pebblebed::Uid.new("!:$298") }.to raise_error Pebblebed::InvalidUid
|
50
95
|
end
|
51
96
|
|
52
97
|
describe "raises an exception when you modify a uid with an invalid value" do
|
53
98
|
let(:uid) { Pebblebed::Uid.new("klass:path$oid") }
|
54
|
-
specify {
|
55
|
-
specify {
|
56
|
-
specify {
|
99
|
+
specify { expect { uid.klass = "!" }.to raise_error Pebblebed::InvalidUid }
|
100
|
+
specify { expect { uid.path = "..." }.to raise_error Pebblebed::InvalidUid }
|
101
|
+
specify { expect { uid.oid = "/" }.to raise_error Pebblebed::InvalidUid }
|
57
102
|
end
|
58
103
|
|
59
104
|
describe "klass" do
|
60
105
|
let(:uid) { Pebblebed::Uid.new("klass:path$oid") }
|
61
106
|
|
62
107
|
it "allows sub-klasses" do
|
63
|
-
|
108
|
+
expect{ uid.klass = "sub.sub.class" }.not_to raise_error
|
64
109
|
end
|
65
110
|
|
66
111
|
describe "is valid" do
|
67
112
|
%w(. - _ 8).each do |nice_character|
|
68
113
|
it "with '#{nice_character}'" do
|
69
|
-
|
114
|
+
expect{ uid.klass = "a#{nice_character}z" }.not_to raise_error
|
70
115
|
end
|
71
116
|
end
|
72
117
|
end
|
@@ -74,7 +119,7 @@ describe Pebblebed::Uid do
|
|
74
119
|
describe "is invalid" do
|
75
120
|
%w(! / : $ % $).each do |funky_character|
|
76
121
|
specify "with '#{funky_character}'" do
|
77
|
-
|
122
|
+
expect{ uid.klass = "a#{funky_character}z" }.to raise_error Pebblebed::InvalidUid
|
78
123
|
end
|
79
124
|
end
|
80
125
|
end
|
@@ -90,107 +135,107 @@ describe Pebblebed::Uid do
|
|
90
135
|
"post:some.path$oid",
|
91
136
|
].each do |oid|
|
92
137
|
specify "'#{oid}' is a valid oid if GCI escaped" do
|
93
|
-
Pebblebed::Uid.valid_oid?(CGI.escape(oid)).
|
138
|
+
expect(Pebblebed::Uid.valid_oid?(CGI.escape(oid))).to be_truthy
|
94
139
|
end
|
95
140
|
end
|
96
141
|
|
97
142
|
specify "'abc/123' is an invalid oid" do
|
98
|
-
Pebblebed::Uid.valid_oid?('abc/123').
|
143
|
+
expect(Pebblebed::Uid.valid_oid?('abc/123')).to be_falsey
|
99
144
|
end
|
100
145
|
|
101
146
|
it "can be missing" do
|
102
|
-
Pebblebed::Uid.new('klass:path').oid.
|
147
|
+
expect(Pebblebed::Uid.new('klass:path').oid).to be_nil
|
103
148
|
end
|
104
149
|
|
105
150
|
it "is not valid if it is nil" do
|
106
|
-
Pebblebed::Uid.valid_oid?(nil).
|
151
|
+
expect(Pebblebed::Uid.valid_oid?(nil)).to be_falsey
|
107
152
|
end
|
108
153
|
end
|
109
154
|
|
110
155
|
it "rejects invalid labels for klass" do
|
111
|
-
Pebblebed::Uid.valid_klass?("abc123").
|
112
|
-
Pebblebed::Uid.valid_klass?("abc123!").
|
113
|
-
Pebblebed::Uid.valid_klass?("").
|
156
|
+
expect(Pebblebed::Uid.valid_klass?("abc123")).to be_truthy
|
157
|
+
expect(Pebblebed::Uid.valid_klass?("abc123!")).to be_falsey
|
158
|
+
expect(Pebblebed::Uid.valid_klass?("")).to be_falsey
|
114
159
|
end
|
115
160
|
|
116
161
|
describe "validating paths" do
|
117
|
-
specify { Pebblebed::Uid.valid_path?("").
|
118
|
-
specify { Pebblebed::Uid.valid_path?("abc123").
|
119
|
-
specify { Pebblebed::Uid.valid_path?("abc.123").
|
120
|
-
specify { Pebblebed::Uid.valid_path?("abc.de-f.123").
|
162
|
+
specify { expect(Pebblebed::Uid.valid_path?("")).to be_truthy }
|
163
|
+
specify { expect(Pebblebed::Uid.valid_path?("abc123")).to be_truthy }
|
164
|
+
specify { expect(Pebblebed::Uid.valid_path?("abc.123")).to be_truthy }
|
165
|
+
specify { expect(Pebblebed::Uid.valid_path?("abc.de-f.123")).to be_truthy }
|
121
166
|
|
122
|
-
specify { Pebblebed::Uid.valid_path?("abc!.").
|
123
|
-
specify { Pebblebed::Uid.valid_path?(".").
|
124
|
-
specify { Pebblebed::Uid.valid_path?("ab. 123").
|
167
|
+
specify { expect(Pebblebed::Uid.valid_path?("abc!.")).to be_falsey }
|
168
|
+
specify { expect(Pebblebed::Uid.valid_path?(".")).to be_falsey }
|
169
|
+
specify { expect(Pebblebed::Uid.valid_path?("ab. 123")).to be_falsey }
|
125
170
|
|
126
171
|
context "with wildcards" do
|
127
|
-
specify { Pebblebed::Uid.valid_path?('*').
|
128
|
-
specify { Pebblebed::Uid.valid_path?('a.b.c.*').
|
129
|
-
specify { Pebblebed::Uid.valid_path?('a.b|c.d').
|
130
|
-
specify { Pebblebed::Uid.valid_path?('a.b|c.*').
|
131
|
-
specify { Pebblebed::Uid.valid_path?('^a').
|
132
|
-
specify { Pebblebed::Uid.valid_path?('^a.b').
|
133
|
-
specify { Pebblebed::Uid.valid_path?('^a.b.c').
|
134
|
-
specify { Pebblebed::Uid.valid_path?('a.^b.c').
|
135
|
-
specify { Pebblebed::Uid.valid_path?('a.^b.c|d.e').
|
136
|
-
specify { Pebblebed::Uid.valid_path?('a.^b.c.*').
|
137
|
-
|
138
|
-
specify { Pebblebed::Uid.valid_path?('*a').
|
139
|
-
specify { Pebblebed::Uid.valid_path?('a*').
|
140
|
-
specify { Pebblebed::Uid.valid_path?('*.b').
|
141
|
-
specify { Pebblebed::Uid.valid_path?('a.*.b').
|
142
|
-
specify { Pebblebed::Uid.valid_path?('|').
|
143
|
-
specify { Pebblebed::Uid.valid_path?('a.|b').
|
144
|
-
specify { Pebblebed::Uid.valid_path?('a.b|').
|
145
|
-
specify { Pebblebed::Uid.valid_path?('a.|b.c').
|
146
|
-
specify { Pebblebed::Uid.valid_path?('a.b|.c').
|
147
|
-
specify { Pebblebed::Uid.valid_path?('^').
|
148
|
-
specify { Pebblebed::Uid.valid_path?('^.a').
|
149
|
-
specify { Pebblebed::Uid.valid_path?('a^').
|
150
|
-
specify { Pebblebed::Uid.valid_path?('a^b.c').
|
172
|
+
specify { expect(Pebblebed::Uid.valid_path?('*')).to be_truthy }
|
173
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.b.c.*')).to be_truthy }
|
174
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.b|c.d')).to be_truthy }
|
175
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.b|c.*')).to be_truthy }
|
176
|
+
specify { expect(Pebblebed::Uid.valid_path?('^a')).to be_truthy }
|
177
|
+
specify { expect(Pebblebed::Uid.valid_path?('^a.b')).to be_truthy }
|
178
|
+
specify { expect(Pebblebed::Uid.valid_path?('^a.b.c')).to be_truthy }
|
179
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.^b.c')).to be_truthy }
|
180
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.^b.c|d.e')).to be_truthy }
|
181
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.^b.c.*')).to be_truthy }
|
182
|
+
|
183
|
+
specify { expect(Pebblebed::Uid.valid_path?('*a')).to be_falsey }
|
184
|
+
specify { expect(Pebblebed::Uid.valid_path?('a*')).to be_falsey }
|
185
|
+
specify { expect(Pebblebed::Uid.valid_path?('*.b')).to be_falsey }
|
186
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.*.b')).to be_falsey }
|
187
|
+
specify { expect(Pebblebed::Uid.valid_path?('|')).to be_falsey }
|
188
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.|b')).to be_falsey }
|
189
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.b|')).to be_falsey }
|
190
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.|b.c')).to be_falsey }
|
191
|
+
specify { expect(Pebblebed::Uid.valid_path?('a.b|.c')).to be_falsey }
|
192
|
+
specify { expect(Pebblebed::Uid.valid_path?('^')).to be_falsey }
|
193
|
+
specify { expect(Pebblebed::Uid.valid_path?('^.a')).to be_falsey }
|
194
|
+
specify { expect(Pebblebed::Uid.valid_path?('a^')).to be_falsey }
|
195
|
+
specify { expect(Pebblebed::Uid.valid_path?('a^b.c')).to be_falsey }
|
151
196
|
end
|
152
197
|
end
|
153
198
|
|
154
199
|
describe "wildcard paths" do
|
155
|
-
specify { Pebblebed::Uid.wildcard_path?('*').
|
156
|
-
specify { Pebblebed::Uid.wildcard_path?('a.b|c.d').
|
157
|
-
specify { Pebblebed::Uid.wildcard_path?('a.^b.d').
|
158
|
-
specify { Pebblebed::Uid.wildcard_path?('a.b.d').
|
200
|
+
specify { expect(Pebblebed::Uid.wildcard_path?('*')).to be_truthy }
|
201
|
+
specify { expect(Pebblebed::Uid.wildcard_path?('a.b|c.d')).to be_truthy }
|
202
|
+
specify { expect(Pebblebed::Uid.wildcard_path?('a.^b.d')).to be_truthy }
|
203
|
+
specify { expect(Pebblebed::Uid.wildcard_path?('a.b.d')).to be_falsey }
|
159
204
|
end
|
160
205
|
|
161
206
|
describe "parsing in place" do
|
162
|
-
specify { Pebblebed::Uid.parse("klass:path$oid").
|
163
|
-
specify { Pebblebed::Uid.parse("post:this.is.a.path.to$object_id").
|
164
|
-
specify { Pebblebed::Uid.parse("post:$object_id").
|
207
|
+
specify { expect(Pebblebed::Uid.parse("klass:path$oid")).to eq ['klass', 'path', 'oid'] }
|
208
|
+
specify { expect(Pebblebed::Uid.parse("post:this.is.a.path.to$object_id")).to eq ['post', 'this.is.a.path.to', 'object_id'] }
|
209
|
+
specify { expect(Pebblebed::Uid.parse("post:$object_id")).to eq ['post', nil, 'object_id'] }
|
165
210
|
end
|
166
211
|
|
167
212
|
describe "validating uids" do
|
168
|
-
specify { Pebblebed::Uid.valid?("a:b.c.d$e").
|
169
|
-
specify { Pebblebed::Uid.valid?("a:$e").
|
170
|
-
specify { Pebblebed::Uid.valid?("a:b.c.d").
|
171
|
-
specify { Pebblebed::Uid.valid?("F**ing H%$#!!!").
|
172
|
-
specify { Pebblebed::Uid.valid?("").
|
173
|
-
specify { Pebblebed::Uid.valid?("bang:").
|
174
|
-
specify { Pebblebed::Uid.valid?(":bang").
|
175
|
-
specify { Pebblebed::Uid.valid?(":bang$paff").
|
176
|
-
specify { Pebblebed::Uid.valid?("$paff").
|
213
|
+
specify { expect(Pebblebed::Uid.valid?("a:b.c.d$e")).to be_truthy }
|
214
|
+
specify { expect(Pebblebed::Uid.valid?("a:$e")).to be_truthy }
|
215
|
+
specify { expect(Pebblebed::Uid.valid?("a:b.c.d")).to be_truthy }
|
216
|
+
specify { expect(Pebblebed::Uid.valid?("F**ing H%$#!!!")).to be_falsey }
|
217
|
+
specify { expect(Pebblebed::Uid.valid?("")).to be_falsey }
|
218
|
+
specify { expect(Pebblebed::Uid.valid?("bang:")).to be_falsey }
|
219
|
+
specify { expect(Pebblebed::Uid.valid?(":bang")).to be_falsey }
|
220
|
+
specify { expect(Pebblebed::Uid.valid?(":bang$paff")).to be_falsey }
|
221
|
+
specify { expect(Pebblebed::Uid.valid?("$paff")).to be_falsey }
|
177
222
|
end
|
178
223
|
|
179
224
|
describe "extracting realm from path" do
|
180
|
-
specify { Pebblebed::Uid.new("klass:realm.other.stuff$3").realm.
|
181
|
-
specify { Pebblebed::Uid.new("klass:realm$3").realm.
|
182
|
-
specify { Pebblebed::Uid.new("klass:realm").realm.
|
183
|
-
specify { Pebblebed::Uid.new("klass:$3").realm.
|
225
|
+
specify { expect(Pebblebed::Uid.new("klass:realm.other.stuff$3").realm).to eq 'realm' }
|
226
|
+
specify { expect(Pebblebed::Uid.new("klass:realm$3").realm).to eq 'realm' }
|
227
|
+
specify { expect(Pebblebed::Uid.new("klass:realm").realm).to eq 'realm' }
|
228
|
+
specify { expect(Pebblebed::Uid.new("klass:$3").realm).to eq nil }
|
184
229
|
end
|
185
230
|
|
186
231
|
describe "equality" do
|
187
232
|
let(:uid) { "klass:realm$3" }
|
188
233
|
it "is dependent on the actual uid" do
|
189
|
-
Pebblebed::Uid.new("klass:realm$3").
|
234
|
+
expect(Pebblebed::Uid.new("klass:realm$3")).to eq Pebblebed::Uid.new("klass:realm$3")
|
190
235
|
end
|
191
236
|
|
192
237
|
it "also works for eql?" do
|
193
|
-
Pebblebed::Uid.new("klass:realm$3").eql?(Pebblebed::Uid.new("klass:realm$3")).
|
238
|
+
expect(Pebblebed::Uid.new("klass:realm$3").eql?(Pebblebed::Uid.new("klass:realm$3"))).to be_truthy
|
194
239
|
end
|
195
240
|
end
|
196
241
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pebblebed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katrina Owen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -289,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
289
289
|
version: '0'
|
290
290
|
requirements: []
|
291
291
|
rubyforge_project: pebblebed
|
292
|
-
rubygems_version: 2.
|
292
|
+
rubygems_version: 2.4.5.1
|
293
293
|
signing_key:
|
294
294
|
specification_version: 4
|
295
295
|
summary: Development tools for working with Pebblebed
|
@@ -309,4 +309,3 @@ test_files:
|
|
309
309
|
- spec/sinatra_spec.rb
|
310
310
|
- spec/spec_helper.rb
|
311
311
|
- spec/uid_spec.rb
|
312
|
-
has_rdoc:
|