Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/corelib/Core/Providers/OpenStackIdentityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public OpenStackIdentityProvider(Uri urlBase, CloudIdentity defaultIdentity, IRe
/// <inheritdoc/>
public override UserAccess GetUserAccess(CloudIdentity identity, bool forceCacheRefresh = false)
{
identity = identity ?? DefaultIdentity;

CloudIdentityWithProject identityWithProject = identity as CloudIdentityWithProject;
if (identityWithProject == null)
return base.GetUserAccess(identityWithProject, forceCacheRefresh);
Expand All @@ -93,13 +95,14 @@ public override UserAccess GetUserAccess(CloudIdentity identity, bool forceCache
Func<UserAccess> refreshCallback =
() =>
{
var projectId = identityWithProject.ProjectId != null ? JToken.FromObject(identityWithProject.ProjectId) : string.Empty;
JObject requestBody = new JObject(
new JProperty("auth", new JObject(
new JProperty("passwordCredentials", new JObject(
new JProperty("username", JValue.CreateString(identityWithProject.Username)),
new JProperty("password", JValue.CreateString(identityWithProject.Password)))),
new JProperty("tenantName", JToken.FromObject(identityWithProject.ProjectName)),
new JProperty("tenantId", JToken.FromObject(identityWithProject.ProjectId)))));
new JProperty("tenantId", projectId))));

var response = ExecuteRESTRequest<JObject>(identity, new Uri(UrlBase, "/v2.0/tokens"), HttpMethod.POST, requestBody, isTokenRequest: true);
if (response == null || response.Data == null)
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/Providers/Rackspace/CloudIdentityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ public virtual Task<IdentityToken> GetTokenAsync(CloudIdentity identity, Cancell
}

/// <inheritdoc/>
public virtual UserAccess Authenticate(CloudIdentity identity)
public virtual UserAccess Authenticate(CloudIdentity identity = null)
{
CheckIdentity(identity);

Expand Down

This file was deleted.

32 changes: 32 additions & 0 deletions src/testing/integration/Identity/v2/IdentityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Diagnostics;
using net.openstack.Core.Providers;
using Xunit;
using Xunit.Abstractions;

namespace OpenStack.Identity.v2
{
public class IdentityTests
{
private readonly OpenStackIdentityProvider _identityService;

public IdentityTests(ITestOutputHelper testLog)
{
var testOutput = new XunitTraceListener(testLog);
Trace.Listeners.Add(testOutput);
OpenStackNet.Tracing.Http.Listeners.Add(testOutput);

_identityService = (OpenStackIdentityProvider) TestIdentityProvider.GetIdentityProvider();
}

[Fact]
public void AuthenticateTest()
{
var userAccess = _identityService.Authenticate();
Assert.NotNull(userAccess);
Assert.NotNull(userAccess.Token);
Assert.NotNull(userAccess.Token.Id);
Assert.NotNull(userAccess.ServiceCatalog);
Assert.NotEmpty(userAccess.ServiceCatalog);
}
}
}
78 changes: 78 additions & 0 deletions src/testing/integration/TestIdentityProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using net.openstack.Core.Domain;
using net.openstack.Core.Providers;

namespace OpenStack
{
public class TestIdentityProvider
{
private static readonly string EnvironmentVariablesNotFoundErrorMessage =
"No identity environemnt variables found. Make sure the following environment variables exist: " + Environment.NewLine +
"OPENSTACKNET_IDENTITY_URL" + Environment.NewLine +
"OPENSTACKNET_USER" + Environment.NewLine +
"OPENSTACKNET_PASSWORD" + Environment.NewLine +
"OPENSTACKNET_PROJECT";

public static IIdentityProvider GetIdentityProvider()
{
var identity = GetIdentityFromEnvironment();
var identityEndpoint = GetIdentityEndpointFromEnvironment();
return new OpenStackIdentityProvider(identityEndpoint, identity)
{
ApplicationUserAgent = "CI-BOT"
};
}

public static Uri GetIdentityEndpointFromEnvironment()
{
var identityUrl = Environment.GetEnvironmentVariable("OPENSTACKNET_IDENTITY_URL");
if(!string.IsNullOrEmpty(identityUrl))
return new Uri(identityUrl);

identityUrl = Environment.GetEnvironmentVariable("BAMBOO_OPENSTACKNET_IDENTITY_URL");
if (!string.IsNullOrEmpty(identityUrl))
return new Uri(identityUrl);

throw new Exception(EnvironmentVariablesNotFoundErrorMessage);
}

public static CloudIdentity GetIdentityFromEnvironment()
{
var user = Environment.GetEnvironmentVariable("OPENSTACKNET_USER");
if (!string.IsNullOrEmpty(user))
{
var password = Environment.GetEnvironmentVariable("OPENSTACKNET_PASSWORD");
var projectName = Environment.GetEnvironmentVariable("OPENSTACKNET_PROJECT");

if (!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(projectName))
{
return new CloudIdentityWithProject
{
Username = user,
Password = password,
ProjectName = projectName
};
}
}

user = Environment.GetEnvironmentVariable("BAMBOO_OPENSTACKNET_USER");
if (!string.IsNullOrEmpty(user))
{
var password = Environment.GetEnvironmentVariable("BAMBOO_OPENSTACKNET_PASSWORD");
var projectName = Environment.GetEnvironmentVariable("BAMBOO_OPENSTACKNET_PROJECT");

if (!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(projectName))
{
return new CloudIdentityWithProject
{
Username = user,
Password = password,
ProjectName = projectName
};
}
}

throw new Exception(EnvironmentVariablesNotFoundErrorMessage);
}
}
}
3 changes: 2 additions & 1 deletion src/testing/integration/integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<Compile Include="Bootstrapper.cs" />
<Compile Include="ContentDeliveryNetworks\v1\ContentDeliveryNetworkServiceTests.cs" />
<Compile Include="ContentDeliveryNetworks\v1\ServiceTests.cs" />
<Compile Include="ContentDeliveryNetworks\v1\TestIdentityProvider.cs" />
<Compile Include="Identity\v2\IdentityTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\Rackspace\CloudNetworksTests.cs" />
<Compile Include="Providers\Rackspace\CloudServersTests.cs" />
Expand All @@ -130,6 +130,7 @@
<Compile Include="Providers\Rackspace\UserObjectStorageTests.cs" />
<Compile Include="Providers\Rackspace\UserQueuesTests.cs" />
<Compile Include="Providers\Rackspace\UserServerTests.cs" />
<Compile Include="TestIdentityProvider.cs" />
<Compile Include="XunitTraceListener.cs" />
</ItemGroup>
<ItemGroup>
Expand Down