1 package ch
.cyberduck
.core
.openstack
;
3 import ch
.cyberduck
.core
.AbstractTestCase
;
4 import ch
.cyberduck
.core
.Credentials
;
5 import ch
.cyberduck
.core
.DisabledLoginCallback
;
6 import ch
.cyberduck
.core
.Host
;
7 import ch
.cyberduck
.core
.Local
;
8 import ch
.cyberduck
.core
.LoginOptions
;
9 import ch
.cyberduck
.core
.Profile
;
10 import ch
.cyberduck
.core
.ProfileReaderFactory
;
11 import ch
.cyberduck
.core
.exception
.LoginCanceledException
;
13 import org
.junit
.Test
;
16 import java
.util
.ArrayList
;
18 import ch
.iterate
.openstack
.swift
.Client
;
19 import ch
.iterate
.openstack
.swift
.method
.Authentication10UsernameKeyRequest
;
20 import ch
.iterate
.openstack
.swift
.method
.Authentication20AccessKeySecretKeyRequest
;
21 import ch
.iterate
.openstack
.swift
.method
.Authentication20RAXUsernameKeyRequest
;
22 import ch
.iterate
.openstack
.swift
.method
.Authentication20UsernamePasswordRequest
;
23 import ch
.iterate
.openstack
.swift
.method
.AuthenticationRequest
;
25 import static org
.junit
.Assert
.assertEquals
;
26 import static org
.junit
.Assert
.fail
;
31 public class SwiftAuthenticationServiceTest
extends AbstractTestCase
{
34 public void testGetRequest() throws Exception
{
35 final SwiftAuthenticationService s
= new SwiftAuthenticationService("/v1.0");
36 assertEquals(Client
.AuthVersion
.v20
,
37 s
.getRequest(new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com", new Credentials("u", "P")),
38 new DisabledLoginCallback()).iterator().next().getVersion());
39 assertEquals(Client
.AuthVersion
.v10
,
40 s
.getRequest(new Host(new SwiftProtocol(), "region-b.geo-1.identity.hpcloudsvc.com", new Credentials("u", "P")),
41 new DisabledLoginCallback()).iterator().next().getVersion());
42 assertEquals(Client
.AuthVersion
.v10
,
43 s
.getRequest(new Host(new SwiftProtocol(), "myhost", new Credentials("u", "P")),
44 new DisabledLoginCallback()).iterator().next().getVersion());
45 assertEquals(Client
.AuthVersion
.v10
,
46 s
.getRequest(new Host(new SwiftProtocol(), "myhost", new Credentials("u", "P")),
47 new DisabledLoginCallback()).iterator().next().getVersion());
48 assertEquals("GET", s
.getRequest(new Host(new SwiftProtocol(), "myhost", new Credentials("u", "P")),
49 new DisabledLoginCallback()).iterator().next().getMethod());
50 assertEquals("POST", s
.getRequest(new Host(new SwiftProtocol(), "lon.identity.api.rackspacecloud.com", new Credentials("u", "P")),
51 new DisabledLoginCallback()).iterator().next().getMethod());
52 final Host host
= new Host(new SwiftProtocol(), "identity.openstack.com", new Credentials("u", "P"));
54 assertEquals(URI
.create("https://identity.openstack.com:3451/v1.0"), s
.getRequest(host
, new DisabledLoginCallback()).iterator().next().getURI());
55 assertEquals(Client
.AuthVersion
.v10
, s
.getRequest(host
, new DisabledLoginCallback()).iterator().next().getVersion());
56 assertEquals(Authentication10UsernameKeyRequest
.class, s
.getRequest(host
, new DisabledLoginCallback()).iterator().next().getClass());
60 public void testGetDefault2() throws Exception
{
61 final SwiftAuthenticationService s
= new SwiftAuthenticationService("/v2.0/tokens");
62 assertEquals(Client
.AuthVersion
.v20
,
63 s
.getRequest(new Host(new SwiftProtocol(), "region-b.geo-1.identity.hpcloudsvc.com", new Credentials("tenant:u", "P")),
64 new DisabledLoginCallback()).iterator().next().getVersion());
65 assertEquals(Client
.AuthVersion
.v20
,
66 s
.getRequest(new Host(new SwiftProtocol(), "myhost", new Credentials("tenant:u", "P")),
67 new DisabledLoginCallback()).iterator().next().getVersion());
68 assertEquals(Authentication20UsernamePasswordRequest
.class,
69 new ArrayList
<AuthenticationRequest
>(s
.getRequest(new Host(new SwiftProtocol(), "myhost", new Credentials("tenant:u", "P")),
70 new DisabledLoginCallback())).get(0).getClass());
73 @Test(expected
= LoginCanceledException
.class)
74 public void testGetDefault2NoTenant() throws Exception
{
75 final SwiftAuthenticationService s
= new SwiftAuthenticationService("/v2.0/tokens");
76 final Credentials credentials
= new Credentials("u", "P");
77 assertEquals(Client
.AuthVersion
.v20
,
78 s
.getRequest(new Host(new SwiftProtocol(), "region-b.geo-1.identity.hpcloudsvc.com", credentials
),
79 new DisabledLoginCallback()).iterator().next().getVersion());
83 public void testGetDefault2EmptyTenant() throws Exception
{
84 final SwiftAuthenticationService s
= new SwiftAuthenticationService("/v2.0/tokens");
85 final Host host
= new Host(new SwiftProtocol(), "region-b.geo-1.identity.hpcloudsvc.com", new Credentials("u", "P"));
86 assertEquals(Client
.AuthVersion
.v20
,
88 new DisabledLoginCallback() {
90 public void prompt(final Host bookmark
, final Credentials credentials
,
91 final String title
, final String reason
, final LoginOptions options
) throws LoginCanceledException
{
92 credentials
.setUsername("");
94 }).iterator().next().getVersion());
95 assertEquals(":u", host
.getCredentials().getUsername());
99 public void testProfileHPCloud() throws Exception
{
100 final SwiftAuthenticationService s
= new SwiftAuthenticationService();
101 final Profile profile
= ProfileReaderFactory
.get().read(
102 new Local("profiles/HP Cloud Object Storage.cyberduckprofile"));
103 final Host host
= new Host(profile
, profile
.getDefaultHostname());
105 s
.getRequest(host
, new DisabledLoginCallback());
108 catch(LoginCanceledException e
) {
111 host
.getCredentials().setUsername("tenant:key");
112 assertEquals(URI
.create("https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens"), s
.getRequest(host
,
113 new DisabledLoginCallback()).iterator().next().getURI());
114 assertEquals(Client
.AuthVersion
.v20
, s
.getRequest(host
, new DisabledLoginCallback()).iterator().next().getVersion());
115 assertEquals(Authentication20AccessKeySecretKeyRequest
.class,
116 new ArrayList
<AuthenticationRequest
>(s
.getRequest(host
, new DisabledLoginCallback())).get(2).getClass());
120 public void testProfileLondon() throws Exception
{
121 final SwiftAuthenticationService s
= new SwiftAuthenticationService();
122 final Profile profile
= ProfileReaderFactory
.get().read(
123 new Local("profiles/Rackspace UK.cyberduckprofile"));
124 final Host host
= new Host(profile
, profile
.getDefaultHostname());
125 assertEquals("/v2.0/tokens", profile
.getContext());
126 assertEquals(URI
.create("https://lon.identity.api.rackspacecloud.com/v2.0/tokens"), s
.getRequest(host
, new DisabledLoginCallback()).iterator().next().getURI());
127 assertEquals(Client
.AuthVersion
.v20
, s
.getRequest(host
, new DisabledLoginCallback()).iterator().next().getVersion());
128 assertEquals(Authentication20RAXUsernameKeyRequest
.class, s
.getRequest(host
, new DisabledLoginCallback()).iterator().next().getClass());
132 public void testDefault() throws Exception
{
133 final SwiftAuthenticationService s
= new SwiftAuthenticationService("/v1.0");
134 final Host host
= new Host(new SwiftProtocol(), "myidentityservice.example.net");
135 assertEquals(URI
.create("https://myidentityservice.example.net/v1.0"), s
.getRequest(host
, new DisabledLoginCallback()).iterator().next().getURI());
136 assertEquals(Client
.AuthVersion
.v10
, s
.getRequest(host
, new DisabledLoginCallback()).iterator().next().getVersion());
137 assertEquals(Authentication10UsernameKeyRequest
.class, s
.getRequest(host
, new DisabledLoginCallback()).iterator().next().getClass());
141 public void testEmptyTenant() throws Exception
{
142 final SwiftAuthenticationService s
= new SwiftAuthenticationService("/v2.0/tokens");
143 final Host host
= new Host(new SwiftProtocol(), "auth.lts2.evault.com", new Credentials(
146 s
.getRequest(host
, new DisabledLoginCallback() {
148 public void prompt(Host bookmark
, Credentials credentials
, String title
, String reason
, LoginOptions options
) throws LoginCanceledException
{
149 credentials
.setUsername("");
152 assertEquals(":u", host
.getCredentials().getUsername());
153 s
.getRequest(host
, new DisabledLoginCallback() {
155 public void prompt(Host bookmark
, Credentials credentials
, String title
, String reason
, LoginOptions options
) throws LoginCanceledException
{