cred_hubble 0.0.1.pre → 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +7 -1
  4. data/.travis.yml +3 -1
  5. data/README.md +353 -13
  6. data/cred_hubble.gemspec +3 -0
  7. data/lib/cred_hubble.rb +3 -2
  8. data/lib/cred_hubble/client.rb +119 -13
  9. data/lib/cred_hubble/http/client.rb +39 -4
  10. data/lib/cred_hubble/resources/certificate_credential.rb +25 -0
  11. data/lib/cred_hubble/resources/credential.rb +32 -0
  12. data/lib/cred_hubble/resources/credential_collection.rb +21 -0
  13. data/lib/cred_hubble/resources/credential_factory.rb +41 -0
  14. data/lib/cred_hubble/resources/immutable_resource.rb +2 -2
  15. data/lib/cred_hubble/resources/json_credential.rb +13 -0
  16. data/lib/cred_hubble/resources/password_credential.rb +13 -0
  17. data/lib/cred_hubble/resources/permission.rb +10 -0
  18. data/lib/cred_hubble/resources/permission_collection.rb +21 -0
  19. data/lib/cred_hubble/resources/resource.rb +10 -0
  20. data/lib/cred_hubble/resources/resources.rb +15 -0
  21. data/lib/cred_hubble/resources/{base_resource.rb → rest_resource.rb} +6 -2
  22. data/lib/cred_hubble/resources/rsa_credential.rb +24 -0
  23. data/lib/cred_hubble/resources/ssh_credential.rb +39 -0
  24. data/lib/cred_hubble/resources/user_credential.rb +39 -0
  25. data/lib/cred_hubble/resources/value_credential.rb +13 -0
  26. data/lib/cred_hubble/version.rb +1 -1
  27. data/spec/cred_hubble/client_spec.rb +487 -3
  28. data/spec/cred_hubble/http/client_spec.rb +347 -53
  29. data/spec/cred_hubble/resources/certificate_credential_spec.rb +49 -0
  30. data/spec/cred_hubble/resources/credential_collection_spec.rb +59 -0
  31. data/spec/cred_hubble/resources/credential_factory_spec.rb +154 -0
  32. data/spec/cred_hubble/resources/credential_spec.rb +10 -0
  33. data/spec/cred_hubble/resources/json_credential_spec.rb +52 -0
  34. data/spec/cred_hubble/resources/password_credential_spec.rb +41 -0
  35. data/spec/cred_hubble/resources/permission_collection_spec.rb +87 -0
  36. data/spec/cred_hubble/resources/permission_spec.rb +36 -0
  37. data/spec/cred_hubble/resources/rsa_credential_spec.rb +46 -0
  38. data/spec/cred_hubble/resources/ssh_credential_spec.rb +73 -0
  39. data/spec/cred_hubble/resources/user_credential_spec.rb +72 -0
  40. data/spec/cred_hubble/resources/value_credential_spec.rb +42 -0
  41. data/spec/support/shared_examples/resource_examples.rb +49 -0
  42. metadata +57 -5
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CredHubble::Resources::CredentialCollection do
4
+ let(:json) do
5
+ '{
6
+ "data":[
7
+ {
8
+ "type":"value",
9
+ "version_created_at":"2017-10-03T04:12:21Z",
10
+ "id":"5298e0e4-c3f5-4c73-a156-9ffce4c137f5",
11
+ "name":"/hello-dolly-credz",
12
+ "value":"Put on your Sunday clothes there\'s lots of world out there"
13
+ },
14
+ {
15
+ "type":"value",
16
+ "version_created_at":"2017-10-03T04:12:19Z",
17
+ "id":"6980ec59-c7e6-449a-b525-298648cfe6a7",
18
+ "name":"/hello-dolly-credz",
19
+ "value":"Get out the brilliantine and dime cigars"
20
+ },
21
+ {
22
+ "type":"value",
23
+ "version_created_at":"2017-10-02T01:56:54Z",
24
+ "id":"3e709d6e-585c-4526-ac0d-fe99316f2255",
25
+ "name":"/hello-dolly-credz",
26
+ "value":"We\'re gonna find adventure in the evening air"
27
+ }
28
+ ]
29
+ }'
30
+ end
31
+
32
+ subject { CredHubble::Resources::CredentialCollection.from_json(json) }
33
+
34
+ describe '.from_json' do
35
+ subject { CredHubble::Resources::CredentialCollection }
36
+
37
+ it 'deserializes all of the credentials into Credential objects' do
38
+ credentials = subject.from_json(json).data
39
+ expect(credentials).to all(be_a(CredHubble::Resources::ValueCredential))
40
+ expect(credentials.map(&:name)).to match_array(%w[/hello-dolly-credz /hello-dolly-credz /hello-dolly-credz])
41
+ expect(credentials.map(&:id)).to match_array(
42
+ %w[
43
+ 5298e0e4-c3f5-4c73-a156-9ffce4c137f5
44
+ 6980ec59-c7e6-449a-b525-298648cfe6a7
45
+ 3e709d6e-585c-4526-ac0d-fe99316f2255
46
+ ]
47
+ )
48
+ end
49
+
50
+ it_behaves_like 'a JSON deserializing resource'
51
+ end
52
+
53
+ describe '#each' do
54
+ it 'is iterable' do
55
+ expect(subject).to respond_to(:each)
56
+ expect(subject.map(&:name)).to match_array(%w[/hello-dolly-credz /hello-dolly-credz /hello-dolly-credz])
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CredHubble::Resources::CredentialFactory do
4
+ describe '.from_json' do
5
+ subject { CredHubble::Resources::CredentialFactory }
6
+
7
+ context 'when the Credential type is "value"' do
8
+ let(:value_json) do
9
+ '{
10
+ "id": "cdbb371a-cc03-4a6f-aa21-c6461d66ed96",
11
+ "name": "/the-grid",
12
+ "type": "value",
13
+ "value": "biodigital-jazz-man",
14
+ "version_created_at": "1985-01-01T01:01:01Z"
15
+ }'
16
+ end
17
+
18
+ it 'returns instantiates a ValueCredential' do
19
+ expect(subject.from_json(value_json)).to be_a(CredHubble::Resources::ValueCredential)
20
+ end
21
+ end
22
+
23
+ context 'when the Credential type is "json"' do
24
+ let(:json_json) do
25
+ '{
26
+ "id": "f2dcb184-cd60-4306-a858-166f44e8cacf",
27
+ "name": "/backstreets-back-alright",
28
+ "type": "json",
29
+ "value": {
30
+ "title": "Everybody",
31
+ "album": "Backstreet\'s Back",
32
+ "members": ["AJ McLean", "Howie D.", "Nick Carter", "Kevin Richardson", "Brian Littrell"]
33
+ },
34
+ "version_created_at": "1985-01-01T01:01:01Z"
35
+ }'
36
+ end
37
+
38
+ it 'returns instantiates a JsonCredential' do
39
+ expect(subject.from_json(json_json)).to be_a(CredHubble::Resources::JsonCredential)
40
+ end
41
+ end
42
+
43
+ context 'when the Credential type is "password"' do
44
+ let(:password_json) do
45
+ '{
46
+ "id": "b1a124c5-3faf-426f-9f8f-fe695b36a4e2",
47
+ "name": "/top-secret-password",
48
+ "type": "password",
49
+ "value": "p4ssw0rd",
50
+ "version_created_at": "1990-05-18T01:01:01Z"
51
+ }'
52
+ end
53
+
54
+ it 'returns instantiates a PasswordCredential' do
55
+ expect(subject.from_json(password_json)).to be_a(CredHubble::Resources::PasswordCredential)
56
+ end
57
+ end
58
+
59
+ context 'when the Credential type is "user"' do
60
+ let(:user_json) do
61
+ '{
62
+ "id": "15811465-8538-460d-9682-5514d44439fd",
63
+ "name": "/admin-user",
64
+ "type": "user",
65
+ "value": {
66
+ "username": "admin",
67
+ "password": "2582aaf15ec84e3fa3ba682152663a52",
68
+ "password_hash": "8efbef4cec28f228fa948daaf4893ac3638fbae81358ff9020be1d7a9a509fc6:1234"
69
+ },
70
+ "version_created_at": "1990-05-18T01:01:01Z"
71
+ }'
72
+ end
73
+
74
+ it 'returns instantiates a UserCredential' do
75
+ expect(subject.from_json(user_json)).to be_a(CredHubble::Resources::UserCredential)
76
+ end
77
+ end
78
+
79
+ context 'when the Credential type is "certificate"' do
80
+ let(:certificate_json) do
81
+ '{
82
+ "id": "15811465-8538-460d-9682-5514d44439fd",
83
+ "name": "/load-balancer-tls-cert",
84
+ "type": "certificate",
85
+ "value": {
86
+ "ca": "-----BEGIN CERTIFICATE-----\n... CA CERT ...\n-----END CERTIFICATE-----",
87
+ "certificate": "-----BEGIN CERTIFICATE-----\n... CERTIFICATE ...\n-----END CERTIFICATE-----",
88
+ "private_key": "-----BEGIN RSA PRIVATE KEY-----\n... RSA PRIVATE KEY ...\n-----END RSA PRIVATE KEY-----"
89
+ },
90
+ "version_created_at": "1990-05-18T01:01:01Z"
91
+ }'
92
+ end
93
+
94
+ it 'returns instantiates a CertificateCredential' do
95
+ expect(subject.from_json(certificate_json)).to be_a(CredHubble::Resources::CertificateCredential)
96
+ end
97
+ end
98
+
99
+ context 'when the Credential type is "rsa"' do
100
+ let(:rsa_json) do
101
+ '{
102
+ "id": "15811465-8538-460d-9682-5514d44439fd",
103
+ "name": "/rsa-key-1",
104
+ "type": "rsa",
105
+ "value": {
106
+ "public_key": "-----BEGIN PUBLIC KEY-----\n... PUBLIC KEY ...\n-----END PUBLIC KEY-----",
107
+ "private_key": "-----BEGIN RSA PRIVATE KEY-----\n... RSA PRIVATE KEY ...\n-----END RSA PRIVATE KEY-----"
108
+ },
109
+ "version_created_at": "1990-05-18T01:01:01Z"
110
+ }'
111
+ end
112
+
113
+ it 'returns instantiates a RsaCredential' do
114
+ expect(subject.from_json(rsa_json)).to be_a(CredHubble::Resources::RsaCredential)
115
+ end
116
+ end
117
+
118
+ context 'when the Credential type is "ssh"' do
119
+ let(:ssh_json) do
120
+ '{
121
+ "id": "15811465-8538-460d-9682-5514d44439fd",
122
+ "name": "/ssh-key-1",
123
+ "type": "ssh",
124
+ "value": {
125
+ "public_key": "ssh-rsa AAAAB3NzaC1y...",
126
+ "private_key": "-----BEGIN RSA PRIVATE KEY-----\n... RSA PRIVATE KEY ...\n-----END RSA PRIVATE KEY-----",
127
+ "public_key_fingerprint": "9db6ee01f7963db4e8c9966f3c425fd3feeadc148f37b428ddce2a458bd50da6"
128
+ },
129
+ "version_created_at": "1990-05-18T01:01:01Z"
130
+ }'
131
+ end
132
+
133
+ it 'returns instantiates a SshCredential' do
134
+ expect(subject.from_json(ssh_json)).to be_a(CredHubble::Resources::SshCredential)
135
+ end
136
+ end
137
+
138
+ context 'when the Credential type is unknown' do
139
+ let(:value_json_response) do
140
+ '{
141
+ "id": "cdbb371a-cc03-4a6f-aa21-c6461d66ed96",
142
+ "name": "/the-digital-frontier",
143
+ "type": "who-knows-man",
144
+ "value": "🌝",
145
+ "version_created_at": "1985-01-01T01:01:01Z"
146
+ }'
147
+ end
148
+
149
+ it 'returns instantiates a base Credential' do
150
+ expect(subject.from_json(value_json_response)).to be_a(CredHubble::Resources::Credential)
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CredHubble::Resources::Credential do
4
+ describe '.from_json' do
5
+ subject { CredHubble::Resources::Credential }
6
+
7
+ it_behaves_like 'a Credential resource'
8
+ it_behaves_like 'a JSON deserializing resource'
9
+ end
10
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CredHubble::Resources::JsonCredential do
4
+ subject { CredHubble::Resources::JsonCredential.new }
5
+
6
+ let(:json_response) do
7
+ '{
8
+ "id": "f2dcb184-cd60-4306-a858-166f44e8cacf",
9
+ "name": "/backstreets-back-alright",
10
+ "type": "json",
11
+ "value": {
12
+ "title": "Everybody",
13
+ "album": "Backstreet\'s Back",
14
+ "members": ["AJ McLean", "Howie D.", "Nick Carter", "Kevin Richardson", "Brian Littrell"]
15
+ },
16
+ "version_created_at": "1985-01-01T01:01:01Z"
17
+ }'
18
+ end
19
+
20
+ describe '.from_json' do
21
+ subject { CredHubble::Resources::JsonCredential }
22
+
23
+ context 'when the JSON includes the required attributes' do
24
+ it 'instantiates a new JsonCredential object' do
25
+ credential = subject.from_json(json_response)
26
+
27
+ expected_value = {
28
+ 'title' => 'Everybody',
29
+ 'album' => "Backstreet's Back",
30
+ 'members' => ['AJ McLean', 'Howie D.', 'Nick Carter', 'Kevin Richardson', 'Brian Littrell']
31
+ }
32
+
33
+ expect(credential).to be_a(CredHubble::Resources::JsonCredential)
34
+ expect(credential.value).to eq(expected_value)
35
+ end
36
+ end
37
+
38
+ it_behaves_like 'a Credential resource'
39
+ it_behaves_like 'a JSON deserializing resource'
40
+ end
41
+
42
+ describe '#type' do
43
+ it 'returns "json"' do
44
+ subject.type = 'attempting-to-overwrite'
45
+ expect(subject.type).to eq('json')
46
+ end
47
+ end
48
+
49
+ describe '#to_json' do
50
+ it_behaves_like 'a JSON serializing resource'
51
+ end
52
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CredHubble::Resources::PasswordCredential do
4
+ let(:json_response) do
5
+ '{
6
+ "id": "b1a124c5-3faf-426f-9f8f-fe695b36a4e2",
7
+ "name": "/top-secret-password",
8
+ "type": "password",
9
+ "value": "p4ssw0rd",
10
+ "version_created_at": "1990-05-18T01:01:01Z"
11
+ }'
12
+ end
13
+
14
+ describe '.from_json' do
15
+ subject { CredHubble::Resources::PasswordCredential }
16
+
17
+ context 'when the JSON includes the required attributes' do
18
+ it 'instantiates a new PasswordCredential object' do
19
+ credential = subject.from_json(json_response)
20
+
21
+ expect(credential).to be_a(CredHubble::Resources::PasswordCredential)
22
+ expect(credential.value).to eq('p4ssw0rd')
23
+ end
24
+ end
25
+
26
+ it_behaves_like 'a Credential resource'
27
+ it_behaves_like 'a JSON deserializing resource'
28
+ end
29
+
30
+ describe '#type' do
31
+ it 'returns "password"' do
32
+ subject.type = 'attempting-to-overwrite'
33
+
34
+ expect(subject.type).to eq('password')
35
+ end
36
+ end
37
+
38
+ describe '#to_json' do
39
+ it_behaves_like 'a JSON serializing resource'
40
+ end
41
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CredHubble::Resources::PermissionCollection do
4
+ let(:json) do
5
+ '{
6
+ "credential_name": "/uaa-client-credentials",
7
+ "permissions":[
8
+ {
9
+ "actor": "mtls-app:5532f504-bb27-43e1-94e9-bad794238f17",
10
+ "operations": [
11
+ "read",
12
+ "write",
13
+ "delete",
14
+ "read_acl",
15
+ "write_acl"
16
+ ]
17
+ },
18
+ {
19
+ "actor": "uaa-user:b2449249-5b51-4893-ab76-648763653c38",
20
+ "operations": [
21
+ "read",
22
+ "write",
23
+ "delete",
24
+ "read_acl",
25
+ "write_acl"
26
+ ]
27
+ }
28
+ ]
29
+ }'
30
+ end
31
+
32
+ subject { CredHubble::Resources::PermissionCollection.from_json(json) }
33
+
34
+ describe '.from_json' do
35
+ subject { CredHubble::Resources::PermissionCollection }
36
+
37
+ it 'deserializes all of the permissions into Permission objects' do
38
+ permission_collection = subject.from_json(json)
39
+ expect(permission_collection.credential_name).to eq('/uaa-client-credentials')
40
+
41
+ permissions = permission_collection.permissions
42
+ expect(permissions).to all(be_a(CredHubble::Resources::Permission))
43
+ expect(permissions.map(&:actor)).to match_array(
44
+ %w[
45
+ mtls-app:5532f504-bb27-43e1-94e9-bad794238f17
46
+ uaa-user:b2449249-5b51-4893-ab76-648763653c38
47
+ ]
48
+ )
49
+ expect(permissions.first.operations).to match_array(%w[read write delete read_acl write_acl])
50
+ end
51
+
52
+ it_behaves_like 'a JSON deserializing resource'
53
+ end
54
+
55
+ describe '#each' do
56
+ it 'is iterable' do
57
+ expect(subject).to respond_to(:each)
58
+ expect(subject.first).to be_a(CredHubble::Resources::Permission)
59
+ expect(subject.map(&:actor)).to match_array(
60
+ %w[
61
+ mtls-app:5532f504-bb27-43e1-94e9-bad794238f17
62
+ uaa-user:b2449249-5b51-4893-ab76-648763653c38
63
+ ]
64
+ )
65
+ end
66
+ end
67
+
68
+ describe '#empty?' do
69
+ context 'when there are permissions' do
70
+ it 'returns false ' do
71
+ expect(subject.empty?).to be false
72
+ end
73
+ end
74
+
75
+ context 'when are not any permissions' do
76
+ let(:json) do
77
+ '{
78
+ "credential_name": "/uaa-client-credentials",
79
+ "permissions":[]
80
+ }'
81
+ end
82
+ it 'returns true ' do
83
+ expect(subject.empty?).to be true
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CredHubble::Resources::Permission do
4
+ let(:json_response) do
5
+ '{
6
+ "actor": "mtls-app:5532f504-bb27-43e1-94e9-bad794238f17",
7
+ "operations": [
8
+ "read",
9
+ "write",
10
+ "delete",
11
+ "read_acl",
12
+ "write_acl"
13
+ ]
14
+ }'
15
+ end
16
+
17
+ describe '.from_json' do
18
+ subject { CredHubble::Resources::Permission }
19
+
20
+ context 'when the JSON includes the required attributes' do
21
+ it 'instantiates a new Permission object' do
22
+ permission = subject.from_json(json_response)
23
+
24
+ expect(permission).to be_a(CredHubble::Resources::Permission)
25
+ expect(permission.actor).to eq('mtls-app:5532f504-bb27-43e1-94e9-bad794238f17')
26
+ expect(permission.operations).to match_array(%w[read write delete read_acl write_acl])
27
+ end
28
+ end
29
+
30
+ it_behaves_like 'a JSON deserializing resource'
31
+ end
32
+
33
+ describe '#to_json' do
34
+ it_behaves_like 'a JSON serializing resource'
35
+ end
36
+ end