@@ -159,3 +159,95 @@ func TestAuthenticatedClientV2(t *testing.T) {
159
159
th .AssertNoErr (t , err )
160
160
th .CheckEquals (t , "01234567890" , client .TokenID )
161
161
}
162
+
163
+ func TestNewClient (t * testing.T ) {
164
+ client , err := NewClient ("https://example.com" )
165
+ th .AssertNoErr (t , err )
166
+ th .AssertEquals (t , "" , client .IdentityEndpoint )
167
+ th .AssertEquals (t , "https://example.com/" , client .IdentityBase )
168
+
169
+ client , err = NewClient ("https://example.com/" )
170
+ th .AssertNoErr (t , err )
171
+ th .AssertEquals (t , "" , client .IdentityEndpoint )
172
+ th .AssertEquals (t , "https://example.com/" , client .IdentityBase )
173
+
174
+ client , err = NewClient ("https://example.com/v2.0" )
175
+ th .AssertNoErr (t , err )
176
+ th .AssertEquals (t , "https://example.com/v2.0/" , client .IdentityEndpoint )
177
+ th .AssertEquals (t , "https://example.com/" , client .IdentityBase )
178
+
179
+ client , err = NewClient ("https://example.com/v2.0/" )
180
+ th .AssertNoErr (t , err )
181
+ th .AssertEquals (t , "https://example.com/v2.0/" , client .IdentityEndpoint )
182
+ th .AssertEquals (t , "https://example.com/" , client .IdentityBase )
183
+
184
+ client , err = NewClient ("https://example.com/foo/bar" )
185
+ th .AssertNoErr (t , err )
186
+ th .AssertEquals (t , "" , client .IdentityEndpoint )
187
+ th .AssertEquals (t , "https://example.com/foo/bar/" , client .IdentityBase )
188
+
189
+ client , err = NewClient ("https://example.com/foo/bar/" )
190
+ th .AssertNoErr (t , err )
191
+ th .AssertEquals (t , "" , client .IdentityEndpoint )
192
+ th .AssertEquals (t , "https://example.com/foo/bar/" , client .IdentityBase )
193
+
194
+ client , err = NewClient ("https://example.com/foo/bar/v2.0" )
195
+ th .AssertNoErr (t , err )
196
+ th .AssertEquals (t , "https://example.com/foo/bar/v2.0/" , client .IdentityEndpoint )
197
+ th .AssertEquals (t , "https://example.com/foo/bar/" , client .IdentityBase )
198
+
199
+ client , err = NewClient ("https://example.com/foo/bar/v2.0/" )
200
+ th .AssertNoErr (t , err )
201
+ th .AssertEquals (t , "https://example.com/foo/bar/v2.0/" , client .IdentityEndpoint )
202
+ th .AssertEquals (t , "https://example.com/foo/bar/" , client .IdentityBase )
203
+
204
+ client , err = NewClient ("https://example.com/foo/bar/v3/" )
205
+ th .AssertNoErr (t , err )
206
+ th .AssertEquals (t , "https://example.com/foo/bar/v3/" , client .IdentityEndpoint )
207
+ th .AssertEquals (t , "https://example.com/foo/bar/" , client .IdentityBase )
208
+
209
+ client , err = NewClient ("https://example.com/v3" )
210
+ th .AssertNoErr (t , err )
211
+ th .AssertEquals (t , "https://example.com/v3/" , client .IdentityEndpoint )
212
+ th .AssertEquals (t , "https://example.com/" , client .IdentityBase )
213
+
214
+ client , err = NewClient ("https://example.com/v3/" )
215
+ th .AssertNoErr (t , err )
216
+ th .AssertEquals (t , "https://example.com/v3/" , client .IdentityEndpoint )
217
+ th .AssertEquals (t , "https://example.com/" , client .IdentityBase )
218
+
219
+ _ , err = NewClient ("https://example.com/v2.3/" )
220
+ th .AssertErr (t , err )
221
+ expected := fmt .Errorf ("Invalid identity endpoint version %v. Supported versions: v2.0, v3" , "v2.3" )
222
+ th .AssertEquals (t , expected .Error (), err .Error ())
223
+
224
+ _ , err = NewClient ("https://example.com/v2.0/foo" )
225
+ th .AssertErr (t , err )
226
+ expected = fmt .Errorf ("Path suffixes (after version) are not supported." )
227
+ th .AssertEquals (t , expected .Error (), err .Error ())
228
+
229
+ // Does not match regexp, include to base
230
+ client , err = NewClient ("https://example.com/v2a0/" )
231
+ th .AssertNoErr (t , err )
232
+ th .AssertEquals (t , "" , client .IdentityEndpoint )
233
+ th .AssertEquals (t , "https://example.com/v2a0/" , client .IdentityBase )
234
+
235
+ // Does not match regexp, include to base
236
+ client , err = NewClient ("https://example.com/v3api" )
237
+ th .AssertNoErr (t , err )
238
+ th .AssertEquals (t , "" , client .IdentityEndpoint )
239
+ th .AssertEquals (t , "https://example.com/v3api/" , client .IdentityBase )
240
+
241
+ // Matches regexp, invalid version v20.
242
+ _ , err = NewClient ("https://example.com/v20./" )
243
+ th .AssertErr (t , err )
244
+ expected = fmt .Errorf ("Invalid identity endpoint version %v. Supported versions: v2.0, v3" , "v20." )
245
+ th .AssertEquals (t , expected .Error (), err .Error ())
246
+
247
+ // domain contains version
248
+ client , err = NewClient ("https://v3.v2.0example.com/v3/" )
249
+ th .AssertNoErr (t , err )
250
+ th .AssertEquals (t , "https://v3.v2.0example.com/v3/" , client .IdentityEndpoint )
251
+ th .AssertEquals (t , "https://v3.v2.0example.com/" , client .IdentityBase )
252
+
253
+ }
0 commit comments