misty 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8871dd676eb4b94f5ba8c83606aa8c058b3308bd
4
- data.tar.gz: 1189ed46c9ff27f495195777eab3738e868c19c7
3
+ metadata.gz: ef6194d780346c6ece1d31df96eb3ee0b9238cfd
4
+ data.tar.gz: 647ec752cc79508e49f5b7be38197634f787921b
5
5
  SHA512:
6
- metadata.gz: 94215114f14ce374973f08066ec787156b7863740ba85c748cfb7d5c2d29552996ca47d433b893ec3c17c585ec5fa8fc0a46d6a298913db76203ca29b529166f
7
- data.tar.gz: 740e770a49088a9a7c86b8bbc54e8b576837932fcb546ee99da12f67566a977632c282039c56e127ff70135458c77bb7976af57c92dc4e151c8653584d8420fb
6
+ metadata.gz: d44270f88d2790dd75c7c47641c88f1c4bf0217dcfb3baf95ca36b99c2b88d82306791e5a45171c0760a2c5360946c8b406fbc5a5cdc7b7db190aad951444c70
7
+ data.tar.gz: ee7884149c42462497317b8305c5b10edacfe584e44edc6273ce04314daca7339c90b33a8753d4d0f76b1ce1e7361616bcab823a6bd279a6d094be898c636d25
@@ -3,19 +3,22 @@ require 'misty/auth'
3
3
  module Misty
4
4
  class AuthV3 < Misty::Auth
5
5
  def initialize(options, *args)
6
- domain_id = options[:domain_id] ? options[:domain_id] : Misty::DOMAIN_ID
7
- project_domain_id = options[:project_domain_id] ? options[:project_domain_id] : Misty::DOMAIN_ID
8
- user_domain_id = options[:user_domain_id] ? options[:user_domain_id] : Misty::DOMAIN_ID
9
-
10
- @domain = Misty::Auth::Name.new(domain_id, options[:domain])
6
+ if options[:project_id] || options[:project]
7
+ # scope: project
8
+ project_domain_id = options[:project_domain_id] ? options[:project_domain_id] : Misty::DOMAIN_ID
9
+ @project = Misty::Auth::ProjectScope.new(options[:project_id], options[:project])
10
+ @project.domain = Misty::Auth::Name.new(project_domain_id, options[:user_domain])
11
+ else
12
+ # scope: domain
13
+ domain_id = options[:domain_id] ? options[:domain_id] : Misty::DOMAIN_ID
14
+ @domain = Misty::Auth::DomainScope.new(domain_id, options[:domain]) if domain_id || options[:domain]
15
+ end
11
16
 
17
+ user_domain_id = options[:user_domain_id] ? options[:user_domain_id] : Misty::DOMAIN_ID
12
18
  @user = Misty::Auth::User.new(options[:user_id], options[:user])
13
19
  @user.password = options[:password]
14
20
  @user.domain = Misty::Auth::Name.new(user_domain_id, options[:user_domain])
15
21
 
16
- @project = Misty::Auth::Project.new(options[:project_id], options[:project])
17
- @project.domain = Misty::Auth::Name.new(project_domain_id, options[:user_domain])
18
-
19
22
  super(options, *args)
20
23
  end
21
24
 
@@ -29,7 +29,13 @@ module Misty
29
29
  end
30
30
  end
31
31
 
32
- class Project < Name
32
+ class DomainScope < Name
33
+ def identity
34
+ { :domain => super }
35
+ end
36
+ end
37
+
38
+ class ProjectScope < Name
33
39
  include Misty::Auth::Domain
34
40
 
35
41
  def identity
data/lib/misty/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Misty
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -83,28 +83,28 @@ describe Misty::Auth::User do
83
83
  end
84
84
  end
85
85
 
86
- describe Misty::Auth::Project do
86
+ describe Misty::Auth::ProjectScope do
87
87
  describe "#identity" do
88
88
  it "when id is provided it doesn't require domain" do
89
- project = Misty::Auth::Project.new("project_id", "Project")
89
+ project = Misty::Auth::ProjectScope.new("project_id", "Project")
90
90
  project.identity.must_equal ({:project=>{:id=>"project_id"}})
91
91
  end
92
92
 
93
93
  it "when id is nul and name is provided it uses domain id" do
94
- project = Misty::Auth::Project.new(nil, "Project")
94
+ project = Misty::Auth::ProjectScope.new(nil, "Project")
95
95
  project.domain = Misty::Auth::Name.new("default", nil)
96
96
  project.identity.must_equal ({:project=>{:name=>"Project", :domain=>{:id=>"default"}}})
97
97
  end
98
98
 
99
99
  it "when id is nul and name is provided it uses domain name" do
100
- project = Misty::Auth::Project.new(nil, "Project")
100
+ project = Misty::Auth::ProjectScope.new(nil, "Project")
101
101
  project.domain = Misty::Auth::Name.new(nil, "Default")
102
102
  project.identity.must_equal ({:project=>{:name=>"Project", :domain=>{:name=>"Default"}}})
103
103
  end
104
104
 
105
105
  it "raises an error with no project id and no domain are provided" do
106
106
  proc do
107
- project = Misty::Auth::Project.new(nil, "Project")
107
+ project = Misty::Auth::ProjectScope.new(nil, "Project")
108
108
  project.identity
109
109
  end.must_raise Misty::Auth::CredentialsError
110
110
  end
@@ -3,7 +3,7 @@ def auth_response_v3(type, name)
3
3
  { 'methods' => ['password'],
4
4
  'roles' => [{ 'id' => 'id_roles', 'name' => 'admin' }],
5
5
  'expires_at' => '2016-11-29T07:45:29.908554Z',
6
- 'project' => { 'domain' => { 'id' => 'default', 'name' => 'Default' }, 'id' => 'id_project', 'name' => 'admin' },
6
+ 'project' => { 'domain' => { 'id' => 'default', 'name' => 'Default' }, 'id' => 'project_id', 'name' => 'admin' },
7
7
  'catalog' =>
8
8
  [{ 'endpoints' =>
9
9
  [{ 'region_id' => 'regionOne',
@@ -2,41 +2,66 @@ require 'test_helper'
2
2
  require 'auth_helper'
3
3
 
4
4
  describe Misty::Auth do
5
- describe ".new" do
6
- let(:authv3_creds) do
7
- {
8
- :url => "http://localhost:5000",
9
- :user => "admin",
10
- :password => "secret",
11
- :project => "admin",
12
- :domain => "default"
13
- }
14
- end
5
+ let(:log) { Logger.new('/dev/null') }
6
+
7
+ describe Misty::AuthV3 do
8
+ describe "#new" do
9
+ it "authenticates using project scoped authorization" do
10
+ auth = {
11
+ :url => "http://localhost:5000",
12
+ :user_id => "user_id",
13
+ :password => "secret",
14
+ :project_id => "project_id"
15
+ }
16
+
17
+ stub_request(:post, "http://localhost:5000/v3/auth/tokens").
18
+ with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\"user_id\",\"password\":\"secret\"}}},\"scope\":{\"project\":{\"id\":\"project_id\"}}}}",
19
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json'}).
20
+ to_return(:status => 200, :body => JSON.dump(auth_response_v3("identity", "keystone")), :headers => {"x-subject-token"=>"token_data"})
21
+
22
+ Misty::AuthV3.new(auth, false, log)
23
+ end
24
+
25
+ it "authenticates using domain scoped authorization" do
26
+ auth = {
27
+ :url => "http://localhost:5000",
28
+ :user_id => "user_id",
29
+ :password => "secret"
30
+ }
31
+
32
+ stub_request(:post, "http://localhost:5000/v3/auth/tokens").
33
+ with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\"user_id\",\"password\":\"secret\"}}},\"scope\":{\"domain\":{\"id\":\"default\"}}}}",
34
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json'}).
35
+ to_return(:status => 200, :body => JSON.dump(auth_response_v3("identity", "keystone")), :headers => {"x-subject-token"=>"token_data"})
15
36
 
16
- let(:authv2_creds) do
17
- {
18
- :url => "http://localhost:5000",
19
- :user => "admin",
20
- :password => "secret",
21
- :tenant => "admin"
22
- }
37
+ Misty::AuthV3.new(auth, false, log)
38
+ end
23
39
  end
24
40
 
25
- describe Misty::AuthV3 do
26
- it "#new fails when missing credentials" do
41
+ describe "with credentials" do
42
+ let(:authv3_creds) do
43
+ {
44
+ :url => "http://localhost:5000",
45
+ :user => "admin",
46
+ :password => "secret",
47
+ :project => "admin"
48
+ }
49
+ end
50
+
51
+ it "fails when missing credentials" do
27
52
  stub_request(:post, "http://localhost:5000/v3/auth/tokens").
28
- to_return(:status => 200, :body => "{\"token\":{\"catalog\":[]}}", :headers => {"x-subject-token"=>"token_data"})
53
+ to_return(:status => 200, :body => "{\"token\":{\"catalog\":[]}}", :headers => {"x-subject-token"=>"token_data"})
29
54
 
30
55
  proc do
31
- Misty::AuthV3.new({}, false, Logger.new('/dev/null'))
56
+ Misty::AuthV3.new({}, false, log)
32
57
  end.must_raise Misty::Auth::CredentialsError
33
58
  end
34
59
 
35
60
  it "#get_token" do
36
61
  stub_request(:post, "http://localhost:5000/v3/auth/tokens").
37
- to_return(:status => 200, :body => "{\"token\":{\"catalog\":[\"catalog_data\"]}}", :headers => {"x-subject-token"=>"token_data"})
62
+ to_return(:status => 200, :body => "{\"token\":{\"catalog\":[\"catalog_data\"]}}", :headers => {"x-subject-token"=>"token_data"})
38
63
 
39
- auth = Misty::AuthV3.new(authv3_creds, false, Logger.new('/dev/null'))
64
+ auth = Misty::AuthV3.new(authv3_creds, false, log)
40
65
  auth.stub :expired?, false do
41
66
  auth.get_token.must_equal "token_data"
42
67
  end
@@ -44,36 +69,49 @@ describe Misty::Auth do
44
69
 
45
70
  it "#catalog" do
46
71
  stub_request(:post, "http://localhost:5000/v3/auth/tokens").
47
- to_return(:status => 200, :body => "{\"token\":{\"catalog\":[\"catalog_data\"]}}", :headers => {"x-subject-token"=>"token_data"})
72
+ to_return(:status => 200, :body => "{\"token\":{\"catalog\":[\"catalog_data\"]}}", :headers => {"x-subject-token"=>"token_data"})
48
73
 
49
- auth = Misty::AuthV3.new(authv3_creds, false, Logger.new('/dev/null'))
74
+ auth = Misty::AuthV3.new(authv3_creds, false, log)
50
75
  auth.catalog.must_equal ["catalog_data"]
51
76
  end
52
77
 
53
78
  it "#get_endpoint" do
54
79
  stub_request(:post, "http://localhost:5000/v3/auth/tokens").
55
- to_return(:status => 200, :body => JSON.dump(auth_response_v3("identity", "keystone")), :headers => {"x-subject-token"=>"token_data"})
80
+ to_return(:status => 200, :body => JSON.dump(auth_response_v3("identity", "keystone")), :headers => {"x-subject-token"=>"token_data"})
56
81
 
57
- auth = Misty::AuthV3.new(authv3_creds, false, Logger.new('/dev/null'))
82
+ auth = Misty::AuthV3.new(authv3_creds, false, log)
58
83
  auth.get_endpoint(%w{identity}, "regionOne", "public").must_equal "http://localhost"
59
84
  end
60
85
  end
86
+ end
61
87
 
62
- describe Misty::AuthV2 do
63
- it "#new fails when missing credentials" do
88
+ describe Misty::AuthV2 do
89
+ describe "#new" do
90
+ it "fails when missing credentials" do
64
91
  stub_request(:post, "http://localhost:5000/v2.0/tokens").
65
92
  to_return(:status => 200, :body => "{\"access\":{\"token\":{\"id\":\"token_data\"}}}", :headers => {})
66
93
 
67
94
  proc do
68
- Misty::AuthV2.new({}, false, Logger.new('/dev/null'))
95
+ Misty::AuthV2.new({}, false, log)
69
96
  end.must_raise Misty::Auth::CredentialsError
70
97
  end
98
+ end
99
+
100
+ describe "with credentials" do
101
+ let(:authv2_creds) do
102
+ {
103
+ :url => "http://localhost:5000",
104
+ :user => "admin",
105
+ :password => "secret",
106
+ :tenant => "admin"
107
+ }
108
+ end
71
109
 
72
110
  it "#get_token" do
73
111
  stub_request(:post, "http://localhost:5000/v2.0/tokens").
74
112
  to_return(:status => 200, :body => "{\"access\":{\"token\":{\"id\":\"token_data\"},\"serviceCatalog\":[\"catalog_data\"]}}", :headers => {})
75
113
 
76
- auth = Misty::AuthV2.new(authv2_creds, false, Logger.new('/dev/null'))
114
+ auth = Misty::AuthV2.new(authv2_creds, false, log)
77
115
  auth.stub :expired?, false do
78
116
  auth.get_token.must_equal "token_data"
79
117
  end
@@ -83,7 +121,7 @@ describe Misty::Auth do
83
121
  stub_request(:post, "http://localhost:5000/v2.0/tokens").
84
122
  to_return(:status => 200, :body => "{\"access\":{\"token\":{\"id\":\"token_data\"},\"serviceCatalog\":[\"catalog_data\"]}}", :headers => {})
85
123
 
86
- auth = Misty::AuthV2.new(authv2_creds, false, Logger.new('/dev/null'))
124
+ auth = Misty::AuthV2.new(authv2_creds, false, log)
87
125
  auth.catalog.must_equal ["catalog_data"]
88
126
  end
89
127
 
@@ -91,7 +129,7 @@ describe Misty::Auth do
91
129
  stub_request(:post, "http://localhost:5000/v2.0/tokens").
92
130
  to_return(:status => 200, :body => JSON.dump(auth_response_v2("identity", "keystone")), :headers => {"x-subject-token"=>"token_data"})
93
131
 
94
- auth = Misty::AuthV2.new(authv2_creds, false, Logger.new('/dev/null'))
132
+ auth = Misty::AuthV2.new(authv2_creds, false, log)
95
133
  auth.get_endpoint(%w{identity}, "regionOne", "public").must_equal "http://localhost"
96
134
  end
97
135
  end
@@ -4,11 +4,10 @@ require 'auth_helper'
4
4
  describe "Misty::Cloud" do
5
5
  let(:cloud) do
6
6
  auth = {
7
- :url => "http://localhost:5000",
8
- :user => "admin",
9
- :password => "secret",
10
- :project => "admin",
11
- :domain => "default"
7
+ :url => "http://localhost:5000",
8
+ :user => "admin",
9
+ :password => "secret",
10
+ :project => "admin"
12
11
  }
13
12
 
14
13
  Misty::Cloud.new(:auth => auth)
@@ -22,7 +22,6 @@ describe Misty::Cloud do
22
22
  :user => "admin",
23
23
  :password => "secret",
24
24
  :project => "admin",
25
- :domain => "default"
26
25
  }
27
26
  end
28
27
 
@@ -89,8 +88,7 @@ describe Misty::Cloud do
89
88
  authv3_data = {
90
89
  :user => "admin",
91
90
  :password => "secret",
92
- :project => "admin",
93
- :domain => "default"
91
+ :project => "admin"
94
92
  }
95
93
 
96
94
  proc do
@@ -103,8 +101,7 @@ describe Misty::Cloud do
103
101
  :url => "",
104
102
  :user => "admin",
105
103
  :password => "secret",
106
- :project => "admin",
107
- :domain => "default"
104
+ :project => "admin"
108
105
  }
109
106
 
110
107
  proc do
@@ -140,8 +137,7 @@ describe Misty::Cloud do
140
137
  :url => "http://localhost:5000",
141
138
  :user => "admin",
142
139
  :password => "secret",
143
- :project => "admin",
144
- :domain => "default"
140
+ :project => "admin"
145
141
  }
146
142
  end
147
143
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: misty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilles Dubreuil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-21 00:00:00.000000000 Z
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json