Skip to content

Commit

Permalink
Final Changes related to negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooja Adhikari committed Jan 4, 2019
1 parent 7b101d3 commit b5e9276
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.Health.Fhir.Web
{
public static class DevelopmentIdentityProviderRegistrationExtensions
{
private const string WRONGAUDIENCECLIENT = "wrongaudienceclient";
private const string WrongAudienceClient = "wrongaudienceclient";

/// <summary>
/// Adds an in-process identity provider if enabled in configuration.
Expand Down Expand Up @@ -56,7 +56,7 @@ public static IServiceCollection AddDevelopmentIdentityProvider(this IServiceCol
UserClaims = { authorizationConfiguration.RolesClaim },
},
new ApiResource(
WRONGAUDIENCECLIENT,
WrongAudienceClient,
claimTypes: new List<string>() { authorizationConfiguration.RolesClaim, ClaimTypes.Name, ClaimTypes.NameIdentifier })
{
UserClaims = { authorizationConfiguration.RolesClaim },
Expand Down Expand Up @@ -85,7 +85,7 @@ public static IServiceCollection AddDevelopmentIdentityProvider(this IServiceCol
ClientSecrets = { new Secret(applicationConfiguration.Id.Sha256()) },

// scopes that client has access to
AllowedScopes = { DevelopmentIdentityProviderConfiguration.Audience, "wrongaudienceclient" },
AllowedScopes = { DevelopmentIdentityProviderConfiguration.Audience, WrongAudienceClient },

// app roles that the client app may have
Claims = applicationConfiguration.Roles.Select(r => new Claim(authorizationConfiguration.RolesClaim, r)).Concat(new[] { new Claim("appid", applicationConfiguration.Id) }).ToList(),
Expand Down
17 changes: 7 additions & 10 deletions test/Microsoft.Health.Fhir.Tests.E2E/Common/FhirClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,20 @@ private async Task SetupAuthenticationAsync(TestApplication clientApplication, T

private async Task<string> GetBearerToken(TestApplication clientApplication, TestUser user)
{
if (clientApplication.Equals(TestApplications.InvalidClient))
{
return null;
}

var formContent = new FormUrlEncodedContent(user == null ? GetAppSecuritySettings(clientApplication) : GetUserSecuritySettings(clientApplication, user));

HttpResponseMessage tokenResponse = await HttpClient.PostAsync(SecuritySettings.TokenUrl, formContent);

var tokenJson = JObject.Parse(await tokenResponse.Content.ReadAsStringAsync());

if (clientApplication.Equals(TestApplications.InvalidClient))
{
return null;
}

if (tokenJson["access_token"] != null)
{
return tokenJson["access_token"].Value<string>();
}
var bearerToken = tokenJson["access_token"].Value<string>();

return null;
return bearerToken;
}

private List<KeyValuePair<string, string>> GetAppSecuritySettings(TestApplication clientApplication)
Expand Down

0 comments on commit b5e9276

Please sign in to comment.