Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing for Tables Autorest Code #12512

Merged
merged 34 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
576d2be
apply old
eboyd23 Jun 15, 2020
dea2498
apply old
eboyd23 Jun 15, 2020
081200a
testing works on this commit
eboyd23 Jun 16, 2020
f6ea265
stashing
eboyd23 Jun 16, 2020
1e1efd8
additional testing
eboyd23 Jul 1, 2020
2397b88
stashing
eboyd23 Jun 22, 2020
c2e8eb7
stashing
eboyd23 Jun 24, 2020
b2ebec7
adding tests
eboyd23 Jun 25, 2020
d54ae25
fixing format and POM
eboyd23 Jun 25, 2020
ac21a3d
arrange-act-assert formatting
eboyd23 Jun 29, 2020
5086d4a
stashing
eboyd23 Jun 29, 2020
68f0cea
adding tests
eboyd23 Jun 30, 2020
f13cca6
reformat
eboyd23 Jun 30, 2020
d4c187a
remove system prints
eboyd23 Jun 30, 2020
335d646
adding playback jsons
eboyd23 Jun 30, 2020
7133df8
recent changes
eboyd23 Jun 30, 2020
2281563
fix pom
eboyd23 Jul 1, 2020
ba399fe
playback mode
eboyd23 Jul 1, 2020
ca8b84c
fix incorrect changes in readme
eboyd23 Jul 1, 2020
e849c5e
fix pom
eboyd23 Jul 1, 2020
0216fde
fixing pom
eboyd23 Jul 1, 2020
8b9e906
fixing version
eboyd23 Jul 1, 2020
3558d0f
fix impl
eboyd23 Jul 1, 2020
5f24375
fixing checkstyles
eboyd23 Jul 1, 2020
229116a
fixing checkstyles p2
eboyd23 Jul 1, 2020
06e255a
connie edits
eboyd23 Jul 2, 2020
8cb259d
connie edits 2
eboyd23 Jul 2, 2020
9b19368
forgot in last commit
eboyd23 Jul 2, 2020
cef9820
add changelog
eboyd23 Jul 2, 2020
1315b59
connie comments
eboyd23 Jul 6, 2020
74c33b5
fixing pipeline issues
eboyd23 Jul 6, 2020
1351fbe
assertion for setup
eboyd23 Jul 6, 2020
b7f8400
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-java …
eboyd23 Jul 6, 2020
767bfdf
fix impl
eboyd23 Jul 7, 2020
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
Prev Previous commit
Next Next commit
connie edits
  • Loading branch information
eboyd23 committed Jul 6, 2020
commit 06e255ae3fcb37d56b0412f67375ed574ee4315d
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,37 @@ public class TablesSharedKeyCredential {
* @param accountKey key to the storage account
*/
public TablesSharedKeyCredential(String accountName, String accountKey) {
Objects.requireNonNull(accountName, "'accountName' cannot be null.");
Objects.requireNonNull(accountKey, "'accountKey' cannot be null.");
this.accountName = accountName;
this.accountKey = accountKey;
this.accountName = Objects.requireNonNull(accountName, "'accountName' cannot be null.");
this.accountKey = Objects.requireNonNull(accountKey, "'accountKey' cannot be null.");
}

/**
* Generates the Auth Headers
*
* @param requestURL the URL which the request is going to
* @param requestUrl the URL which the request is going to
* @param headers the headers of the request
* @return the auth header
*/
public String generateAuthorizationHeader(URL requestURL, Map<String, String> headers) {
String signature = StorageImplUtils.computeHMac256(this.accountKey, this.buildStringToSign(requestURL,
public String generateAuthorizationHeader(URL requestUrl, Map<String, String> headers) {
String signature = StorageImplUtils.computeHMac256(accountKey, buildStringToSign(requestUrl,
headers));
return String.format(AUTHORIZATION_HEADER_FORMAT, this.accountName, signature);
return String.format(AUTHORIZATION_HEADER_FORMAT, accountName, signature);
}

/**
* creates the String to Sign
*
* @param requestURL the URL which the request is going to
* @param requestUrl the Url which the request is going to
* @param headers the headers of the request
* @return a string to sign for the request
*/
private String buildStringToSign(URL requestURL, Map<String, String> headers) {
String dateHeader = headers.containsKey("x-ms-date") ? "" : this.getStandardHeaderValue(headers,
"Date");
private String buildStringToSign(URL requestUrl, Map<String, String> headers) {
String dateHeader = headers.containsKey("x-ms-date")
? ""
: this.getStandardHeaderValue(headers, "Date");
return String.join("\n",
dateHeader, //date
this.getCanonicalizedResource(requestURL)); //Canonicalized resource
getCanonicalizedResource(requestUrl)); //Canonicalized resource
}

/**
Expand All @@ -79,20 +78,19 @@ private String getStandardHeaderValue(Map<String, String> headers, String header
/**
* returns the canonicalized resource needed for a request
*
* @param requestURL the url of the request
* @param requestUrl the url of the request
* @return the string that is the canonicalized resource
*/
private String getCanonicalizedResource(URL requestURL) {
StringBuilder canonicalizedResource = new StringBuilder("/");
canonicalizedResource.append(this.accountName);
if (requestURL.getPath().length() > 0) {
canonicalizedResource.append(requestURL.getPath());
private String getCanonicalizedResource(URL requestUrl) {
StringBuilder canonicalizedResource = new StringBuilder("/").append(accountName);
if (requestUrl.getPath().length() > 0) {
canonicalizedResource.append(requestUrl.getPath());
} else {
canonicalizedResource.append('/');
}

if (requestURL.getQuery() != null) {
Map<String, String[]> queryParams = StorageImplUtils.parseQueryStringSplitValues(requestURL.getQuery());
if (requestUrl.getQuery() != null) {
Map<String, String[]> queryParams = StorageImplUtils.parseQueryStringSplitValues(requestUrl.getQuery());
ArrayList<String> queryParamNames = new ArrayList<>(queryParams.keySet());
Collections.sort(queryParamNames);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.azure.data.tables;


import com.azure.core.http.HttpPipelineCallContext;
import com.azure.core.http.HttpPipelineNextPolicy;
import com.azure.core.http.HttpResponse;
Expand Down Expand Up @@ -34,7 +33,7 @@ public TablesSharedKeyCredentialPolicy(TablesSharedKeyCredential credential) {
* @return an Http response
*/
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
String authorizationValue = this.credential.generateAuthorizationHeader(context.getHttpRequest().getUrl(),
String authorizationValue = credential.generateAuthorizationHeader(context.getHttpRequest().getUrl(),
context.getHttpRequest().getHeaders().toMap());
context.getHttpRequest().setHeader("Authorization", authorizationValue);
return next.process();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class AzureTableImplTest extends TestBase {

@Override
protected void beforeTest() {
super.beforeTest();
String connectionString = interceptorManager.isPlaybackMode()
? "DefaultEndpointsProtocol=https;AccountName=dummyAccount;AccountKey=xyzDummy;EndpointSuffix=core.windows.net"
: System.getenv("AZURE_TABLES_CONNECTION_STRING");
Expand All @@ -58,22 +57,22 @@ protected void beforeTest() {
TablesSharedKeyCredential sharedKeyCredential = new TablesSharedKeyCredential(authSettings.getAccount().getName(),
authSettings.getAccount().getAccessKey());

final List<HttpPipelinePolicy> policies = new ArrayList<>();
List<HttpPipelinePolicy> policies = new ArrayList<>();
policies.add(new AddDatePolicy());
policies.add(new AddHeadersPolicy(new HttpHeaders().put("Accept",
OdataMetadataFormat.APPLICATION_JSON_ODATA_MINIMALMETADATA.toString())));
policies.add(new TablesSharedKeyCredentialPolicy(sharedKeyCredential));
policies.add(new HttpLoggingPolicy(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)));

final HttpClient httpClientToUse;
HttpClient httpClientToUse;
if (interceptorManager.isPlaybackMode()) {
httpClientToUse = interceptorManager.getPlaybackClient();
} else {
httpClientToUse = HttpClient.createDefault();
policies.add(interceptorManager.getRecordPolicy());
policies.add(new RetryPolicy());
}
final HttpPipeline pipeline = new HttpPipelineBuilder()
HttpPipeline pipeline = new HttpPipelineBuilder()
.httpClient(httpClientToUse)
.policies(policies.toArray(new HttpPipelinePolicy[0]))
.build();
Expand Down