macaroons 0.4.1 → 0.5.1
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/macaroons/macaroons.rb +6 -34
- data/lib/macaroons/serializers/binary.rb +10 -2
- data/lib/macaroons/serializers/json.rb +3 -3
- data/lib/macaroons/version.rb +1 -1
- data/lib/macaroons.rb +2 -20
- data/macaroons.gemspec +1 -1
- data/spec/integration_spec.rb +21 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b14107765c3e83a14fc187461933dfe1e729e8b0
|
4
|
+
data.tar.gz: 2e84c062ea4002193849926bf7922fc73a81d900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da89cecf838fa7f57ee11ac0fb278a59adcb48cc6a5636a03723c520f2e69ffd9cd9af6cf03e53fe245292da01bc524d77e83231a7e4a4f4ac47e74d7e1f68ca
|
7
|
+
data.tar.gz: 58a3c3bd502981104c3aa409a07ac6e749561d8af8a82456df4a10304aca1de79b89329f9c7fb2b75073672cb09b9b779a3062cc1e915c98835b58ee92c249d3
|
data/lib/macaroons/macaroons.rb
CHANGED
@@ -1,26 +1,17 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
1
3
|
require 'macaroons/raw_macaroon'
|
2
4
|
|
3
5
|
module Macaroons
|
4
6
|
class Macaroon
|
7
|
+
extend Forwardable
|
8
|
+
|
5
9
|
def initialize(key: nil, identifier: nil, location: nil, raw_macaroon: nil)
|
6
10
|
@raw_macaroon = raw_macaroon || RawMacaroon.new(key: key, identifier: identifier, location: location)
|
7
11
|
end
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def location
|
14
|
-
@raw_macaroon.location
|
15
|
-
end
|
16
|
-
|
17
|
-
def signature
|
18
|
-
@raw_macaroon.signature
|
19
|
-
end
|
20
|
-
|
21
|
-
def caveats
|
22
|
-
@raw_macaroon.caveats
|
23
|
-
end
|
13
|
+
def_delegators :@raw_macaroon, :identifier, :location, :signature, :caveats,
|
14
|
+
:serialize, :serialize_json, :add_first_party_caveat, :add_third_party_caveat, :prepare_for_request
|
24
15
|
|
25
16
|
def self.from_binary(serialized)
|
26
17
|
raw_macaroon = RawMacaroon.from_binary(serialized: serialized)
|
@@ -32,32 +23,13 @@ module Macaroons
|
|
32
23
|
macaroon = Macaroons::Macaroon.new(raw_macaroon: raw_macaroon)
|
33
24
|
end
|
34
25
|
|
35
|
-
def serialize
|
36
|
-
@raw_macaroon.serialize()
|
37
|
-
end
|
38
|
-
|
39
|
-
def serialize_json
|
40
|
-
@raw_macaroon.serialize_json()
|
41
|
-
end
|
42
|
-
|
43
|
-
def add_first_party_caveat(predicate)
|
44
|
-
@raw_macaroon.add_first_party_caveat(predicate)
|
45
|
-
end
|
46
|
-
|
47
26
|
def first_party_caveats
|
48
27
|
caveats.select(&:first_party?)
|
49
28
|
end
|
50
29
|
|
51
|
-
def add_third_party_caveat(caveat_key, caveat_id, caveat_location)
|
52
|
-
@raw_macaroon.add_third_party_caveat(caveat_key, caveat_id, caveat_location)
|
53
|
-
end
|
54
|
-
|
55
30
|
def third_party_caveats
|
56
31
|
caveats.select(&:third_party?)
|
57
32
|
end
|
58
33
|
|
59
|
-
def prepare_for_request(macaroon)
|
60
|
-
@raw_macaroon.prepare_for_request(macaroon)
|
61
|
-
end
|
62
34
|
end
|
63
35
|
end
|
@@ -23,12 +23,12 @@ module Macaroons
|
|
23
23
|
'signature',
|
24
24
|
Utils.unhexlify(macaroon.signature)
|
25
25
|
)
|
26
|
-
|
26
|
+
base64_url_encode(combined)
|
27
27
|
end
|
28
28
|
|
29
29
|
def deserialize(serialized)
|
30
30
|
caveats = []
|
31
|
-
decoded =
|
31
|
+
decoded = base64_url_decode(serialized)
|
32
32
|
|
33
33
|
index = 0
|
34
34
|
|
@@ -85,5 +85,13 @@ module Macaroons
|
|
85
85
|
[key, value]
|
86
86
|
end
|
87
87
|
|
88
|
+
def base64_url_decode(str)
|
89
|
+
str += '=' * (4 - str.length.modulo(4)).modulo(4)
|
90
|
+
Base64.urlsafe_decode64(str)
|
91
|
+
end
|
92
|
+
|
93
|
+
def base64_url_encode(str)
|
94
|
+
Base64.urlsafe_encode64(str).tr('=', '')
|
95
|
+
end
|
88
96
|
end
|
89
97
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'multi_json'
|
2
2
|
|
3
3
|
module Macaroons
|
4
4
|
class JsonSerializer
|
@@ -10,11 +10,11 @@ module Macaroons
|
|
10
10
|
caveats: macaroon.caveats.map!(&:to_h),
|
11
11
|
signature: macaroon.signature
|
12
12
|
}
|
13
|
-
|
13
|
+
MultiJson.dump(serialized)
|
14
14
|
end
|
15
15
|
|
16
16
|
def deserialize(serialized)
|
17
|
-
deserialized =
|
17
|
+
deserialized = MultiJson.load(serialized)
|
18
18
|
macaroon = Macaroons::RawMacaroon.new(key: 'no_key', identifier: deserialized['identifier'], location: deserialized['location'])
|
19
19
|
deserialized['caveats'].each do |c|
|
20
20
|
caveat = Macaroons::Caveat.new(c['cid'], c['vid'], c['cl'])
|
data/lib/macaroons/version.rb
CHANGED
data/lib/macaroons.rb
CHANGED
@@ -1,24 +1,6 @@
|
|
1
1
|
require 'macaroons/macaroons'
|
2
2
|
require 'macaroons/verifier'
|
3
3
|
|
4
|
-
|
5
|
-
class
|
6
|
-
def new(location: location, identifier: identifier, key: key)
|
7
|
-
Macaroons::Macaroon.new(location:location, identifier:identifier, key:key)
|
8
|
-
end
|
9
|
-
|
10
|
-
def from_binary(serialized)
|
11
|
-
Macaroons::Macaroon.from_binary(serialized)
|
12
|
-
end
|
13
|
-
|
14
|
-
def from_json(serialized)
|
15
|
-
Macaroons::Macaroon.from_json(serialized)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Verifier
|
20
|
-
def self.new()
|
21
|
-
Macaroons::Verifier.new()
|
22
|
-
end
|
23
|
-
end
|
4
|
+
class Macaroon < Macaroons::Macaroon
|
5
|
+
class Verifier < Macaroons::Verifier; end
|
24
6
|
end
|
data/macaroons.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
spec.required_ruby_version = "~> 2.0"
|
19
|
-
spec.add_dependency "
|
19
|
+
spec.add_dependency "multi_json", "~> 1.10.1"
|
20
20
|
spec.add_dependency "rbnacl", "~> 3.1.2"
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "> 1.3"
|
data/spec/integration_spec.rb
CHANGED
@@ -38,6 +38,18 @@ describe 'Macaroon' do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
context 'when serilizing as binary with padding' do
|
42
|
+
it 'should strip the padding' do
|
43
|
+
m = Macaroon.new(
|
44
|
+
location: 'http://mybank/',
|
45
|
+
identifier: 'we used our secret key',
|
46
|
+
key: 'this is our super secret key; only we should know it'
|
47
|
+
)
|
48
|
+
m.add_first_party_caveat('test = a caveat')
|
49
|
+
expect(m.serialize()).to eql('MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAxOGNpZCB0ZXN0ID0gYSBjYXZlYXQKMDAyZnNpZ25hdHVyZSAOX3fqTY3ESWO6a5DZltZZReCDkfjbcdwSQDTdBrhApwo')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
41
53
|
context 'when deserializing binary' do
|
42
54
|
it 'should deserialize properly' do
|
43
55
|
m = Macaroon.from_binary(
|
@@ -47,6 +59,15 @@ describe 'Macaroon' do
|
|
47
59
|
end
|
48
60
|
end
|
49
61
|
|
62
|
+
context 'when deserializing binary without padding' do
|
63
|
+
it 'should add padding' do
|
64
|
+
m = Macaroon.from_binary(
|
65
|
+
'MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAxOGNpZCB0ZXN0ID0gYSBjYXZlYXQKMDAyZnNpZ25hdHVyZSAOX3fqTY3ESWO6a5DZltZZReCDkfjbcdwSQDTdBrhApwo='
|
66
|
+
)
|
67
|
+
expect(m.signature).to eql('0e5f77ea4d8dc44963ba6b90d996d65945e08391f8db71dc124034dd06b840a7')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
50
71
|
context 'when serilizing as json' do
|
51
72
|
it 'should serialize properly' do
|
52
73
|
m = Macaroon.new(
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: macaroons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Cordell
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: multi_json
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 1.10.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: 1.10.1
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rbnacl
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|