Beispiel #1
0
        public async Task CanCreateFloatingIpWithCreatedResponse()
        {
            var payload = @"{
                ""floatingip"":
                    {
                        ""router_id"": ""fafac59b-a94a-4525-8700-f4f448e0ac97"",
                        ""status"": ""ACTIVE"",
                        ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
                        ""floating_network_id"": ""3eaab3f7-d3f2-430f-aa73-d07f39aae8f4"",
                        ""fixed_ip_address"": ""10.0.0.2"",
                        ""floating_ip_address"": ""172.0.0.1"",
                        ""port_id"": ""9da94672-6e6b-446c-9579-3dd5484b31fd"",
                        ""id"": ""12345""
                    }
            }";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.Created);

            this.NetworkServiceRestClient.Responses.Enqueue(restResp);

            var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
            var result = await client.CreateFloatingIp("12345");

            Assert.IsNotNull(result);

            Assert.AreEqual("12345", result.Id);
            Assert.AreEqual("172.0.0.1", result.FloatingIpAddress);
            Assert.AreEqual(FloatingIpStatus.Active, result.Status);
        }
Beispiel #2
0
        public async Task CanAuthenticateWithOkResponse()
        {
            var creds = GetValidCredentials();

            var expectedToken = "HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb";

            var payload = @"{
                                                ""access"": {
                                                    ""token"": {
                                                        ""expires"": ""2014-03-18T10:59:46.355Z"",
                                                        ""id"": ""HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb"",
                                                        ""tenant"": {
                                                            ""id"": ""10244656540440"",
                                                            ""name"": ""10255892528404-Project""
                                                        }
                                                    },
                                                    ""serviceCatalog"":[{
                                                        ""name"": ""Object Storage"",
                                                        ""type"": ""object-store"",
                                                        ""endpoints"": [
                                                            {
                                                                ""tenantId"": ""10244656540440"",
                                                                ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
                                                                ""region"": ""region-a.geo-1"",
                                                                ""versionId"": ""1.0"",
                                                                ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
                                                                ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
                                                            },
                                                            {
                                                                ""tenantId"": ""10244656540440"",
                                                                ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
                                                                ""region"": ""region-b.geo-1"",
                                                                ""versionId"": ""1"",
                                                                ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
                                                                ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
                                                            }
                                                        ]
                                                    }]
                                                }
                                            }";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);

            this.RestClient.Response = restResp;

            var client =
                new IdentityServicePocoClientFactory().Create(creds, "Swift", CancellationToken.None, this.ServiceLocator) as
                IdentityServicePocoClient;
            var result = await client.Authenticate();

            Assert.IsNotNull(result);
            Assert.AreEqual(creds.UserName, result.UserName);
            Assert.AreEqual(creds.Password, result.Password);
            Assert.AreEqual(creds.TenantId, result.TenantId);
            Assert.AreEqual(expectedToken, result.AccessTokenId);
            Assert.AreEqual(1, result.ServiceCatalog.Count());
        }
Beispiel #3
0
        public async Task ExceptionthrownWhenDeletingFloatingIpAndServerError()
        {
            var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);

            this.NetworkServiceRestClient.Responses.Enqueue(restResp);

            var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
            await client.DeleteFloatingIp("12345");
        }
Beispiel #4
0
        public async Task CanDeleteFloatingIpWithNoContentResponse()
        {
            var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);

            this.NetworkServiceRestClient.Responses.Enqueue(restResp);

            var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
            await client.DeleteFloatingIp("12345");
        }
Beispiel #5
0
        public async Task ExceptionthrownWhenCreatingFloatingIpAndNotAuthed()
        {
            var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);

            this.NetworkServiceRestClient.Responses.Enqueue(restResp);

            var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
            await client.CreateFloatingIp("12345");
        }
Beispiel #6
0
        public async Task CannotAuthenticateWithNotFoundResponse()
        {
            var creds = GetValidCredentials();

            var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NotFound);

            this.RestClient.Response = restResp;

            var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
            await client.Authenticate();
        }
Beispiel #7
0
        public async Task AuthenticationDoesNotResolveRegionIfCredRegionSupplied()
        {
            var expectedRegion = "Some region";
            var creds          = GetValidCredentials();

            creds.SetRegion(expectedRegion);
            var payload = @"{
                                                ""access"": {
                                                    ""token"": {
                                                        ""expires"": ""2014-03-18T10:59:46.355Z"",
                                                        ""id"": ""HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb"",
                                                        ""tenant"": {
                                                            ""id"": ""10244656540440"",
                                                            ""name"": ""10255892528404-Project""
                                                        }
                                                    },
                                                    ""serviceCatalog"":[{
                                                        ""name"": ""Object Storage"",
                                                        ""type"": ""object-store"",
                                                        ""endpoints"": [
                                                            {
                                                                ""tenantId"": ""10244656540440"",
                                                                ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
                                                                ""region"": ""region-a.geo-1"",
                                                                ""versionId"": ""1.0"",
                                                                ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
                                                                ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
                                                            },
                                                            {
                                                                ""tenantId"": ""10244656540440"",
                                                                ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
                                                                ""region"": ""region-b.geo-1"",
                                                                ""versionId"": ""1"",
                                                                ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
                                                                ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
                                                            }
                                                        ]
                                                    }]
                                                }
                                            }";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);

            this.RestClient.Response = restResp;

            var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
            var result = await client.Authenticate();

            Assert.AreEqual(expectedRegion, result.Region);
        }
Beispiel #8
0
        public async Task CanGetNetworksWithOkResponse()
        {
            var payload = @"{
                ""networks"": [
                    {
                        ""status"": ""ACTIVE"",
                        ""subnets"": [
                            ""d3839504-ec4c-47a4-b7c7-07af079a48bb""
                        ],
                        ""name"": ""myNetwork"",
                        ""router:external"": false,
                        ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
                        ""admin_state_up"": true,
                        ""shared"": false,
                        ""id"": ""12345""
                    }
                ]
            }";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);

            this.NetworkServiceRestClient.Responses.Enqueue(restResp);

            var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
            var result = await client.GetNetworks();

            Assert.IsNotNull(result);

            var networks = result.ToList();

            Assert.AreEqual(1, networks.Count());

            var network = networks.First();

            Assert.AreEqual("myNetwork", network.Name);
            Assert.AreEqual("12345", network.Id);
            Assert.AreEqual(NetworkStatus.Active, network.Status);
        }