@@ -66,6 +66,156 @@ public function test_it_authenticates()
66
66
$ this ->assertEquals ('http://example.org:8080/v1/AUTH_e00abf65afca49609eedd163c515cf10 ' , $ url );
67
67
}
68
68
69
+ public function test_it_authenticates_using_cache_token ()
70
+ {
71
+ $ cachedToken = [
72
+ 'is_domain ' => false ,
73
+ 'methods ' => [
74
+ 'password ' ,
75
+ ],
76
+ 'roles ' => [
77
+ 0 => [
78
+ 'id ' => 'ce40dfb7a1b14f8a875194fe2944e00c ' ,
79
+ 'name ' => 'admin ' ,
80
+ ],
81
+ ],
82
+ 'expires_at ' => '2199-11-24T04:47:49.000000Z ' ,
83
+ 'project ' => [
84
+ 'domain ' => [
85
+ 'id ' => 'default ' ,
86
+ 'name ' => 'Default ' ,
87
+ ],
88
+ 'id ' => 'c41b19de8aac4ecdb0f04ede718206c5 ' ,
89
+ 'name ' => 'admin ' ,
90
+ ],
91
+ 'catalog ' => [
92
+ [
93
+ 'endpoints ' => [
94
+ [
95
+ 'region_id ' => 'RegionOne ' ,
96
+ 'url ' => 'http://example.org:8080/v1/AUTH_e00abf65afca49609eedd163c515cf10 ' ,
97
+ 'region ' => 'RegionOne ' ,
98
+ 'interface ' => 'public ' ,
99
+ 'id ' => 'hhh ' ,
100
+ ]
101
+ ],
102
+ 'type ' => 'object-store ' ,
103
+ 'id ' => 'aaa ' ,
104
+ 'name ' => 'swift ' ,
105
+ ],
106
+ ],
107
+ 'user ' => [
108
+ 'domain ' => [
109
+ 'id ' => 'default ' ,
110
+ 'name ' => 'Default ' ,
111
+ ],
112
+ 'id ' => '37a36374b074428985165e80c9ab28c8 ' ,
113
+ 'name ' => 'admin ' ,
114
+ ],
115
+ 'audit_ids ' => [
116
+ 'X0oY7ouSQ32vEpbgDJTDpA ' ,
117
+ ],
118
+ 'issued_at ' => '2017-11-24T03:47:49.000000Z ' ,
119
+ 'id ' => 'bb4f74cfb73847ec9ca947fa61d799d3 ' ,
120
+ ];
121
+
122
+ $ userOptions = [
123
+ 'user ' => [
124
+ 'id ' => '{userId} ' ,
125
+ 'password ' => '{userPassword} ' ,
126
+ 'domain ' => ['id ' => '{domainId} ' ]
127
+ ],
128
+ 'scope ' => [
129
+ 'project ' => ['id ' => '{projectId} ' ]
130
+ ],
131
+ 'catalogName ' => 'swift ' ,
132
+ 'catalogType ' => 'object-store ' ,
133
+ 'region ' => 'RegionOne ' ,
134
+ 'cachedToken ' => $ cachedToken
135
+ ];
136
+
137
+ list ($ token , $ url ) = $ this ->service ->authenticate ($ userOptions );
138
+
139
+ $ this ->assertInstanceOf (Models \Token::class, $ token );
140
+ $ this ->assertEquals ('http://example.org:8080/v1/AUTH_e00abf65afca49609eedd163c515cf10 ' , $ url );
141
+ }
142
+
143
+
144
+ /**
145
+ * @expectedException \RuntimeException
146
+ * @expectedExceptionMessage Cached token has expired
147
+ */
148
+ public function test_it_authenticates_and_throws_exception_when_authenticate_with_expired_cached_token ()
149
+ {
150
+ $ cachedToken = [
151
+ 'is_domain ' => false ,
152
+ 'methods ' => [
153
+ 'password ' ,
154
+ ],
155
+ 'roles ' => [
156
+ 0 => [
157
+ 'id ' => 'ce40dfb7a1b14f8a875194fe2944e00c ' ,
158
+ 'name ' => 'admin ' ,
159
+ ],
160
+ ],
161
+ 'expires_at ' => '2000-11-24T04:47:49.000000Z ' ,
162
+ 'project ' => [
163
+ 'domain ' => [
164
+ 'id ' => 'default ' ,
165
+ 'name ' => 'Default ' ,
166
+ ],
167
+ 'id ' => 'c41b19de8aac4ecdb0f04ede718206c5 ' ,
168
+ 'name ' => 'admin ' ,
169
+ ],
170
+ 'catalog ' => [
171
+ [
172
+ 'endpoints ' => [
173
+ [
174
+ 'region_id ' => 'RegionOne ' ,
175
+ 'url ' => 'http://example.org:8080/v1/AUTH_e00abf65afca49609eedd163c515cf10 ' ,
176
+ 'region ' => 'RegionOne ' ,
177
+ 'interface ' => 'public ' ,
178
+ 'id ' => 'hhh ' ,
179
+ ]
180
+ ],
181
+ 'type ' => 'object-store ' ,
182
+ 'id ' => 'aaa ' ,
183
+ 'name ' => 'swift ' ,
184
+ ],
185
+ ],
186
+ 'user ' => [
187
+ 'domain ' => [
188
+ 'id ' => 'default ' ,
189
+ 'name ' => 'Default ' ,
190
+ ],
191
+ 'id ' => '37a36374b074428985165e80c9ab28c8 ' ,
192
+ 'name ' => 'admin ' ,
193
+ ],
194
+ 'audit_ids ' => [
195
+ 'X0oY7ouSQ32vEpbgDJTDpA ' ,
196
+ ],
197
+ 'issued_at ' => '2017-11-24T03:47:49.000000Z ' ,
198
+ 'id ' => 'bb4f74cfb73847ec9ca947fa61d799d3 ' ,
199
+ ];
200
+
201
+ $ userOptions = [
202
+ 'user ' => [
203
+ 'id ' => '{userId} ' ,
204
+ 'password ' => '{userPassword} ' ,
205
+ 'domain ' => ['id ' => '{domainId} ' ]
206
+ ],
207
+ 'scope ' => [
208
+ 'project ' => ['id ' => '{projectId} ' ]
209
+ ],
210
+ 'catalogName ' => 'swift ' ,
211
+ 'catalogType ' => 'object-store ' ,
212
+ 'region ' => 'RegionOne ' ,
213
+ 'cachedToken ' => $ cachedToken
214
+ ];
215
+
216
+ $ this ->service ->authenticate ($ userOptions );
217
+ }
218
+
69
219
/**
70
220
* @expectedException \RuntimeException
71
221
*/
0 commit comments