Skip to content

Commit

Permalink
Add ApiIssueUpdateContract, support for OpenId auth in ApiContract (#…
Browse files Browse the repository at this point in the history
…5047)

* generated the code.

* record tests

* Version and Change Log update
  • Loading branch information
solankisamir authored and dsgouda committed Nov 21, 2018
1 parent f8895c2 commit 0afa2cf
Show file tree
Hide file tree
Showing 75 changed files with 14,434 additions and 12,298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ public void TryCreateApiManagementService()
Assert.Equal(this.serviceName, service.Name);
}


public string GetOpenIdMetadataEndpointUrl()
{
return "https://" + TestUtilities.GenerateName("provider") + "." + TestUtilities.GenerateName("endpoint");
}

public string GetLocation(string regionIn = "US")
{
var provider = this.resourcesClient.Providers.Get("Microsoft.ApiManagement");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public async Task CreateListUpdateDelete()
// create autorization server
string newApiAuthorizationServerId = TestUtilities.GenerateName("authorizationServerId");
string newApiId = TestUtilities.GenerateName("apiid");
string newOpenApiId = TestUtilities.GenerateName("openApiid");
string openIdNoSecret = TestUtilities.GenerateName("openId");

try
{
Expand Down Expand Up @@ -102,7 +104,7 @@ public async Task CreateListUpdateDelete()
{
AuthorizationServerId = newApiAuthorizationServerId,
Scope = newApiAuthorizationScope
}
}
};

var createdApiContract = testBase.client.Api.CreateOrUpdate(
Expand All @@ -121,7 +123,7 @@ public async Task CreateListUpdateDelete()
Header = subscriptionKeyParametersHeader,
Query = subscriptionKeyQueryStringParamName
},
AuthenticationSettings = newApiAuthenticationSettings
AuthenticationSettings = newApiAuthenticationSettings
});

// get new api to check it was added
Expand Down Expand Up @@ -187,6 +189,73 @@ public async Task CreateListUpdateDelete()
Assert.True(apiGetResponse.Protocols.Contains(Protocol.Http));
Assert.True(apiGetResponse.Protocols.Contains(Protocol.Https));

// add an api with OpenId authentication settings
// create a openId connect provider
string openIdProviderName = TestUtilities.GenerateName("openIdName");
string metadataEndpoint = testBase.GetOpenIdMetadataEndpointUrl();
string clientId = TestUtilities.GenerateName("clientId");
var openIdConnectCreateParameters = new OpenidConnectProviderContract(openIdProviderName,
metadataEndpoint, clientId);

var openIdCreateResponse = testBase.client.OpenIdConnectProvider.CreateOrUpdate(
testBase.rgName,
testBase.serviceName,
openIdNoSecret,
openIdConnectCreateParameters);

Assert.NotNull(openIdCreateResponse);
Assert.Equal(openIdProviderName, openIdCreateResponse.DisplayName);
Assert.Equal(openIdNoSecret, openIdCreateResponse.Name);

string newOpenIdApiName = TestUtilities.GenerateName("apiname");
string newOpenIdApiDescription = TestUtilities.GenerateName("apidescription");
string newOpenIdApiPath = "newOpenapiPath";
string newOpenIdApiServiceUrl = "http://newechoapi2.cloudapp.net/api";
string newOpenIdAuthorizationScope = TestUtilities.GenerateName("oauth2scope");
var newnewOpenIdAuthenticationSettings = new AuthenticationSettingsContract
{
Openid = new OpenIdAuthenticationSettingsContract
{
OpenidProviderId = openIdCreateResponse.Name,
BearerTokenSendingMethods = new[] { BearerTokenSendingMethods.AuthorizationHeader }
}
};

var createdOpenApiIdContract = testBase.client.Api.CreateOrUpdate(
testBase.rgName,
testBase.serviceName,
newOpenApiId,
new ApiCreateOrUpdateParameter
{
DisplayName = newOpenIdApiName,
Description = newOpenIdApiDescription,
Path = newOpenIdApiPath,
ServiceUrl = newOpenIdApiServiceUrl,
Protocols = new List<Protocol?> { Protocol.Https, Protocol.Http },
SubscriptionKeyParameterNames = new SubscriptionKeyParameterNamesContract
{
Header = subscriptionKeyParametersHeader,
Query = subscriptionKeyQueryStringParamName
},
AuthenticationSettings = newnewOpenIdAuthenticationSettings
});

// get new api to check it was added
var openApiGetResponse = testBase.client.Api.Get(testBase.rgName, testBase.serviceName, newOpenApiId);
Assert.NotNull(openApiGetResponse);
Assert.Equal(newOpenApiId, openApiGetResponse.Name);
Assert.Equal(newOpenIdApiName, openApiGetResponse.DisplayName);
Assert.Equal(newOpenIdApiDescription, openApiGetResponse.Description);
Assert.Equal(newOpenIdApiPath, openApiGetResponse.Path);
Assert.Equal(newOpenIdApiServiceUrl, openApiGetResponse.ServiceUrl);
Assert.Equal(subscriptionKeyParametersHeader, openApiGetResponse.SubscriptionKeyParameterNames.Header);
Assert.Equal(subscriptionKeyQueryStringParamName, openApiGetResponse.SubscriptionKeyParameterNames.Query);
Assert.Equal(2, openApiGetResponse.Protocols.Count);
Assert.True(openApiGetResponse.Protocols.Contains(Protocol.Http));
Assert.True(openApiGetResponse.Protocols.Contains(Protocol.Https));
Assert.NotNull(openApiGetResponse.AuthenticationSettings.Openid);
Assert.Equal(openIdCreateResponse.Name, openApiGetResponse.AuthenticationSettings.Openid.OpenidProviderId);

// list with paging
listResponse = testBase.client.Api.ListByService(
testBase.rgName,
Expand All @@ -201,7 +270,7 @@ public async Task CreateListUpdateDelete()

Assert.NotNull(listResponse);
Assert.Single(listResponse);
Assert.Empty(listResponse.NextPageLink);
Assert.NotNull(listResponse.NextPageLink);

// delete the api
testBase.client.Api.Delete(
Expand All @@ -220,10 +289,28 @@ public async Task CreateListUpdateDelete()
{
Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
}

// delete the api
testBase.client.Api.Delete(
testBase.rgName,
testBase.serviceName,
newOpenApiId,
"*");

// get the deleted api to make sure it was deleted
try
{
testBase.client.Api.Get(testBase.rgName, testBase.serviceName, newOpenApiId);
throw new Exception("This code should not have been executed.");
}
catch (ErrorResponseException ex)
{
Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
}
}
finally
{
// delete authorization server
// delete api server
testBase.client.Api.Delete(
testBase.rgName,
testBase.serviceName,
Expand All @@ -235,6 +322,19 @@ public async Task CreateListUpdateDelete()
testBase.serviceName,
newApiAuthorizationServerId,
"*");

// delete api server
testBase.client.Api.Delete(
testBase.rgName,
testBase.serviceName,
newOpenApiId,
"*");

testBase.client.OpenIdConnectProvider.Delete(
testBase.rgName,
testBase.serviceName,
openIdNoSecret,
"*");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public async Task CreateListUpdateDelete()
Assert.NotNull(diagnostics);
Assert.Empty(diagnostics);

// create new diagnostic
string diagnosticId = TestUtilities.GenerateName("diagnoticId");
// create new diagnostic, supported Ids are applicationinsights, azuremonitor
string diagnosticId = "applicationinsights";
string loggerId = TestUtilities.GenerateName("appInsights");

try
Expand Down Expand Up @@ -92,16 +92,6 @@ public async Task CreateListUpdateDelete()
Assert.Equal(loggerId, loggerContractList.GetEnumerator().ToIEnumerable().First().Name);
Assert.Equal(LoggerType.ApplicationInsights, loggerContractList.GetEnumerator().ToIEnumerable().First().LoggerType);

// delete the diagnostic logger relationship
await testBase.client.DiagnosticLogger.DeleteAsync(
testBase.rgName,
testBase.serviceName,
diagnosticId,
loggerId);

var entitystatus = testBase.client.DiagnosticLogger.CheckEntityExists(testBase.rgName, testBase.serviceName, diagnosticId, loggerId);
Assert.False(entitystatus);

// check the diagnostic entity etag
var diagnosticTag = await testBase.client.Diagnostic.GetEntityTagAsync(
testBase.rgName,
Expand Down Expand Up @@ -140,8 +130,8 @@ await testBase.client.Logger.DeleteAsync(
}
finally
{
testBase.client.Logger.Delete(testBase.rgName, testBase.serviceName, loggerId, "*");
testBase.client.Diagnostic.Delete(testBase.rgName, testBase.serviceName, diagnosticId, "*");
testBase.client.Logger.Delete(testBase.rgName, testBase.serviceName, loggerId, "*");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,35 @@ public async Task CreateUpdateDelete()
Assert.Equal(issueData.Name, newissueId);
Assert.Equal(adminUser.Id, issueData.UserId);

// update the issue
var updateTitle = TestUtilities.GenerateName("updatedTitle");
var updateDescription = TestUtilities.GenerateName("updateddescription");

var issueUpdateContract = new IssueUpdateContract()
{
Description = updateDescription,
Title = updateTitle
};

await testBase.client.ApiIssue.UpdateAsync(
testBase.rgName,
testBase.serviceName,
echoApi.Name,
newissueId,
issueUpdateContract);

// get the issue
issueData = await testBase.client.ApiIssue.GetAsync(
testBase.rgName,
testBase.serviceName,
echoApi.Name,
newissueId);
Assert.NotNull(issueData);
Assert.Equal(issueData.Name, newissueId);
Assert.Equal(adminUser.Id, issueData.UserId);
Assert.Equal(updateTitle, issueData.Title);
Assert.Equal(updateDescription, issueData.Description);

// get commments on issue. there should be none initially
var emptyCommentList = await testBase.client.ApiIssueComment.ListByServiceAsync(
testBase.rgName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task CreateListUpdateDelete()
{
// create a openId connect provider
string openIdProviderName = TestUtilities.GenerateName("openIdName");
string metadataEndpoint = GetHttpsUrl();
string metadataEndpoint = testBase.GetOpenIdMetadataEndpointUrl();
string clientId = TestUtilities.GenerateName("clientId");
var openIdConnectCreateParameters = new OpenidConnectProviderContract(openIdProviderName,
metadataEndpoint, clientId);
Expand Down Expand Up @@ -64,7 +64,7 @@ public async Task CreateListUpdateDelete()

// create a Secret property
string openIdProviderName2 = TestUtilities.GenerateName("openIdName");
string metadataEndpoint2 = GetHttpsUrl();
string metadataEndpoint2 = testBase.GetOpenIdMetadataEndpointUrl();
string clientId2 = TestUtilities.GenerateName("clientId");
string clientSecret = TestUtilities.GenerateName("clientSecret");
var openIdConnectCreateParameters2 = new OpenidConnectProviderContract(openIdProviderName2,
Expand Down Expand Up @@ -148,7 +148,7 @@ await testBase.client.OpenIdConnectProvider.DeleteAsync(
Assert.NotNull(openIdConnectProviderTag.ETag);

// patch the openId Connect Provider
string updateMetadataEndpoint = GetHttpsUrl();
string updateMetadataEndpoint = testBase.GetOpenIdMetadataEndpointUrl();
string updatedClientId = TestUtilities.GenerateName("updatedClient");
testBase.client.OpenIdConnectProvider.Update(
testBase.rgName,
Expand Down Expand Up @@ -211,10 +211,5 @@ await testBase.client.OpenIdConnectProvider.DeleteAsync(
}
}
}

static string GetHttpsUrl()
{
return "https://" + TestUtilities.GenerateName("provider") + "." + TestUtilities.GenerateName("endpoint");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ public async Task CreateListUpdateDelete()
Assert.NotNull(genrateTokenResponse);
Assert.NotNull(genrateTokenResponse.Value);

// get the useridentity
var currentUserIdentity = await testBase.client.User.GetIdentityAsync(
testBase.rgName,
testBase.serviceName);
Assert.NotNull(currentUserIdentity);
Assert.NotNull(currentUserIdentity.Id);

// remove the user
testBase.client.User.Delete(
testBase.rgName,
Expand Down
Loading

0 comments on commit 0afa2cf

Please sign in to comment.