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
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public async Task CreateListUpdateDelete()
Assert.NotNull(apiGetResponse.AuthenticationSettings);
Assert.NotNull(apiGetResponse.AuthenticationSettings.OAuth2);
Assert.Equal(newApiAuthorizationServerId, apiGetResponse.AuthenticationSettings.OAuth2.AuthorizationServerId);
Assert.Single(apiGetResponse.AuthenticationSettings.OAuth2AuthenticationSettings);
Assert.Equal(newApiAuthorizationServerId, apiGetResponse.AuthenticationSettings.OAuth2AuthenticationSettings.First().AuthorizationServerId);
Assert.Empty(apiGetResponse.AuthenticationSettings.OpenidAuthenticationSettings);

// get the API Entity Tag
ApiGetEntityTagHeaders apiTag = testBase.client.Api.GetEntityTag(
Expand All @@ -155,7 +158,7 @@ public async Task CreateListUpdateDelete()
Assert.NotNull(apiTag);
Assert.NotNull(apiTag.ETag);

// patch added api
// patch added api with OAuth2AuthenticationSettings
string patchedName = TestUtilities.GenerateName("patchedname");
string patchedDescription = TestUtilities.GenerateName("patchedDescription");
string patchedPath = TestUtilities.GenerateName("patchedPath");
Expand All @@ -171,7 +174,14 @@ public async Task CreateListUpdateDelete()
Path = patchedPath,
AuthenticationSettings = new AuthenticationSettingsContract
{
OAuth2 = null
OAuth2AuthenticationSettings = new[]
{
new OAuth2AuthenticationSettingsContract
{
AuthorizationServerId = newApiAuthorizationServerId,
Scope = newApiAuthorizationScope
}
}
}
},
apiTag.ETag);
Expand All @@ -190,6 +200,10 @@ public async Task CreateListUpdateDelete()
Assert.Equal(2, apiGetResponse.Protocols.Count);
Assert.True(apiGetResponse.Protocols.Contains(Protocol.Http));
Assert.True(apiGetResponse.Protocols.Contains(Protocol.Https));
Assert.NotNull(apiGetResponse.AuthenticationSettings.OAuth2);
Assert.Single(apiGetResponse.AuthenticationSettings.OAuth2AuthenticationSettings);
Assert.Equal(newApiAuthorizationServerId, apiGetResponse.AuthenticationSettings.OAuth2AuthenticationSettings.First().AuthorizationServerId);
Assert.Empty(apiGetResponse.AuthenticationSettings.OpenidAuthenticationSettings);

// get the latest API Entity Tag
apiTag = testBase.client.Api.GetEntityTag(
Expand Down Expand Up @@ -305,6 +319,10 @@ public async Task CreateListUpdateDelete()
Assert.True(openApiGetResponse.Protocols.Contains(Protocol.Https));
Assert.NotNull(openApiGetResponse.AuthenticationSettings.Openid);
Assert.Equal(openIdCreateResponse.Name, openApiGetResponse.AuthenticationSettings.Openid.OpenidProviderId);
Assert.Empty(openApiGetResponse.AuthenticationSettings.OAuth2AuthenticationSettings);
Assert.Single(openApiGetResponse.AuthenticationSettings.OpenidAuthenticationSettings);
Assert.Equal(openIdCreateResponse.Name, openApiGetResponse.AuthenticationSettings.OpenidAuthenticationSettings.First().OpenidProviderId);


// list with paging
listResponse = testBase.client.Api.ListByService(
Expand All @@ -322,6 +340,84 @@ public async Task CreateListUpdateDelete()
Assert.Single(listResponse);
Assert.NotNull(listResponse.NextPageLink);


// patch added api with OpenidAuthenticationSettings
apiTag = testBase.client.Api.GetEntityTag(
testBase.rgName,
testBase.serviceName,
newApiId);

testBase.client.Api.Update(
testBase.rgName,
testBase.serviceName,
newApiId,
new ApiUpdateContract
{
AuthenticationSettings = new AuthenticationSettingsContract
{
OpenidAuthenticationSettings = new[]
{
new OpenIdAuthenticationSettingsContract
{
OpenidProviderId = openIdCreateResponse.Name
}
}
}
},
apiTag.ETag);

// get patched api to check it was patched
var patchedOpenApiGetResponse = testBase.client.Api.Get(testBase.rgName, testBase.serviceName, newOpenApiId);

Assert.NotNull(patchedOpenApiGetResponse.AuthenticationSettings.Openid);
Assert.Equal(openIdCreateResponse.Name, patchedOpenApiGetResponse.AuthenticationSettings.Openid.OpenidProviderId);
Assert.Empty(patchedOpenApiGetResponse.AuthenticationSettings.OAuth2AuthenticationSettings);
Assert.Single(patchedOpenApiGetResponse.AuthenticationSettings.OpenidAuthenticationSettings);
Assert.Equal(openIdCreateResponse.Name, patchedOpenApiGetResponse.AuthenticationSettings.OpenidAuthenticationSettings.First().OpenidProviderId);

// patch with both OAuth2 and Oauth2AuthentiationSettings should fail
var oauth2Contract = new OAuth2AuthenticationSettingsContract
{
AuthorizationServerId = newApiAuthorizationServerId,
Scope = newApiAuthorizationScope
};

Assert.Throws<ErrorResponseException>(() =>
testBase.client.Api.Update(
testBase.rgName,
testBase.serviceName,
newApiId,
new ApiUpdateContract
{
AuthenticationSettings = new AuthenticationSettingsContract
{
OAuth2 = oauth2Contract,
OAuth2AuthenticationSettings = new[] { oauth2Contract }
}
},
apiTag.ETag));

// patch with both OpenId and OpenidAuthenticationSettings should fail
var openIdContract = new OpenIdAuthenticationSettingsContract
{
OpenidProviderId = openIdCreateResponse.Name
};

Assert.Throws<ErrorResponseException>(() =>
testBase.client.Api.Update(
testBase.rgName,
testBase.serviceName,
newApiId,
new ApiUpdateContract
{
AuthenticationSettings = new AuthenticationSettingsContract
{
Openid = openIdContract,
OpenidAuthenticationSettings = new[] { openIdContract }
}
},
apiTag.ETag));

// delete the api
testBase.client.Api.Delete(
testBase.rgName,
Expand All @@ -340,6 +436,7 @@ public async Task CreateListUpdateDelete()
Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
}


// delete the api
testBase.client.Api.Delete(
testBase.rgName,
Expand Down Expand Up @@ -512,6 +609,9 @@ await testBase.client.AuthorizationServer.CreateOrUpdateAsync(
Assert.NotNull(apiGetResponse.AuthenticationSettings.OAuth2);
Assert.Equal(newApiAuthorizationServerId, apiGetResponse.AuthenticationSettings.OAuth2.AuthorizationServerId);
Assert.True(apiGetResponse.SubscriptionRequired);
Assert.Single(apiGetResponse.AuthenticationSettings.OAuth2AuthenticationSettings);
Assert.Equal(newApiAuthorizationServerId, apiGetResponse.AuthenticationSettings.OAuth2AuthenticationSettings.First().AuthorizationServerId);
Assert.Empty(apiGetResponse.AuthenticationSettings.OpenidAuthenticationSettings);

var newApiOperations = await testBase.client.ApiOperation.ListByApiAsync(
testBase.rgName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public async Task CreateListUpdateDelete()
Assert.Equal(authorizationServerContract.TokenBodyParameters.Count, getResponse.Body.TokenBodyParameters.Count);
Assert.True(getResponse.Body.TokenBodyParameters.All(p => authorizationServerContract.TokenBodyParameters.Any(p1 => p1.Name.Equals(p.Name, StringComparison.OrdinalIgnoreCase) && p1.Value.Equals(p.Value, StringComparison.OrdinalIgnoreCase))));

// check default values for UseInTestConsole and UseInApiDocumentation
Assert.True(getResponse.Body.UseInTestConsole);
Assert.False(getResponse.Body.UseInApiDocumentation);


var secretsResponse = await testBase.client.AuthorizationServer.ListSecretsAsync(
testBase.rgName,
testBase.serviceName,
Expand All @@ -127,7 +132,9 @@ public async Task CreateListUpdateDelete()
// update
var updateParameters = new AuthorizationServerUpdateContract
{
GrantTypes = new List<string> { GrantType.AuthorizationCode, GrantType.ResourceOwnerPassword }
GrantTypes = new List<string> { GrantType.AuthorizationCode, GrantType.ResourceOwnerPassword },
UseInApiDocumentation = true,
UseInTestConsole = false
};

testBase.client.AuthorizationServer.Update(
Expand Down Expand Up @@ -167,6 +174,8 @@ public async Task CreateListUpdateDelete()
Assert.Equal(authorizationServerContract.SupportState, getResponse.Body.SupportState);
Assert.Equal(authorizationServerContract.TokenBodyParameters.Count, getResponse.Body.TokenBodyParameters.Count);
Assert.True(getResponse.Body.TokenBodyParameters.All(p => authorizationServerContract.TokenBodyParameters.Any(p1 => p1.Name.Equals(p.Name, StringComparison.OrdinalIgnoreCase) && p1.Value.Equals(p.Value, StringComparison.OrdinalIgnoreCase))));
Assert.False(getResponse.Body.UseInTestConsole);
Assert.True(getResponse.Body.UseInApiDocumentation);

// delete
testBase.client.AuthorizationServer.Delete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public async Task CreateListUpdateDelete()
Assert.Null(openIdConnectProviderContract.ClientSecret);
Assert.Null(openIdConnectProviderContract.Description);

// check default values for UseInTestConsole and UseInApiDocumentation
Assert.True(openIdConnectProviderContract.UseInTestConsole);
Assert.False(openIdConnectProviderContract.UseInApiDocumentation);

// create a Secret property
string openIdProviderName2 = TestUtilities.GenerateName("openIdName");
string metadataEndpoint2 = testBase.GetOpenIdMetadataEndpointUrl();
Expand Down Expand Up @@ -161,7 +165,9 @@ await testBase.client.OpenIdConnectProvider.DeleteAsync(
new OpenidConnectProviderUpdateContract
{
MetadataEndpoint = updateMetadataEndpoint,
ClientId = updatedClientId
ClientId = updatedClientId,
UseInTestConsole = true,
UseInApiDocumentation = false
},
openIdConnectProviderTag.ETag);

Expand All @@ -180,6 +186,8 @@ await testBase.client.OpenIdConnectProvider.DeleteAsync(
Assert.Equal(updateMetadataEndpoint, getResponseOpendId2.Body.MetadataEndpoint);
Assert.Null(getResponseOpendId2.Body.ClientSecret);
Assert.NotNull(getResponseOpendId2.Body.Description);
Assert.True(getResponseOpendId2.Body.UseInTestConsole);
Assert.False(getResponseOpendId2.Body.UseInApiDocumentation);

var secretsResponse = await testBase.client.OpenIdConnectProvider.ListSecretsAsync(
testBase.rgName,
Expand Down
Loading