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 all commits
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
3 changes: 3 additions & 0 deletions sdk/tables/azure-data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Release History

## 1.0.0-beta.1 (Unreleased)
27 changes: 25 additions & 2 deletions sdk/tables/azure-data-tables/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.azure</groupId>
Expand Down Expand Up @@ -31,7 +32,6 @@ Licensed under the MIT License.
<tag>HEAD</tag>
</scm>

<!-- CosmosTableSkip - Needed temporary values to 10% not fail. -->
<properties>
<jacoco.skip.coverage.check>true</jacoco.skip.coverage.check>
</properties>
Expand All @@ -42,6 +42,29 @@ Licensed under the MIT License.
<artifactId>azure-core</artifactId>
<version>1.6.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-common</artifactId>
<version>12.7.0</version> <!-- {x-version-update;com.azure:azure-storage-common;dependency} -->
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<version>3.3.5.RELEASE</version> <!-- {x-version-update;io.projectreactor:reactor-test;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.3.1</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.data.tables;
eboyd23 marked this conversation as resolved.
Show resolved Hide resolved

import com.azure.storage.common.implementation.StorageImplUtils;

import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

/**
* A Class which helps generate the shared key credentials for a given storage account to create a Http requests to
* access Azure Tables
*/
public class TablesSharedKeyCredential {
private static final String AUTHORIZATION_HEADER_FORMAT = "SharedKeyLite %s:%s";
private final String accountName;
private final String accountKey;

/**
* Constructor for TableSharedKeyCredential Class
*
* @param accountName name of the storage account
* @param accountKey key to the storage account
*/
public TablesSharedKeyCredential(String accountName, String 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 headers the headers of the request
* @return the auth header
*/
public String generateAuthorizationHeader(URL requestUrl, Map<String, String> headers) {
String signature = StorageImplUtils.computeHMac256(accountKey, buildStringToSign(requestUrl,
headers));
return String.format(AUTHORIZATION_HEADER_FORMAT, accountName, signature);
}

/**
* creates the String to Sign
*
* @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");
return String.join("\n",
dateHeader, //date
getCanonicalizedResource(requestUrl)); //Canonicalized resource
}

/**
* gets necessary headers if the request does not already contain them
*
* @param headers a map of the headers which the request has
* @param headerName the name of the header to get the standard header for
* @return the standard header for the given name
*/
private String getStandardHeaderValue(Map<String, String> headers, String headerName) {
String headerValue = headers.get(headerName);
return headerValue == null ? "" : headerValue;
}


/**
* returns the canonicalized resource needed for a 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("/").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());
ArrayList<String> queryParamNames = new ArrayList<>(queryParams.keySet());

Collections.sort(queryParamNames);

for (String queryParamName : queryParamNames) {
String[] queryParamValues = queryParams.get(queryParamName);

Arrays.sort(queryParamValues);

String queryParamValuesStr = String.join(",", queryParamValues);

if (queryParamName.equalsIgnoreCase("comp")) {
canonicalizedResource.append("?").append(queryParamName.toLowerCase(Locale.ROOT)).append("=")
.append(queryParamValuesStr);
}
}
}
return canonicalizedResource.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.data.tables;

import com.azure.core.http.HttpPipelineCallContext;
import com.azure.core.http.HttpPipelineNextPolicy;
import com.azure.core.http.HttpResponse;
import com.azure.core.http.policy.HttpPipelinePolicy;
import reactor.core.publisher.Mono;

/**
* This class helps authenticate an Http request for the Tables service
*/
public final class TablesSharedKeyCredentialPolicy implements HttpPipelinePolicy {

private final TablesSharedKeyCredential credential;

/**
* constructor for the TablesSharedKeyCredentialPolicy class
*
* @param credential the credentials of the account
*/
public TablesSharedKeyCredentialPolicy(TablesSharedKeyCredential credential) {
this.credential = credential;
}

/**
* creates an Http response
*
* @param context the context of the http pipeline
* @param next the next Http pipeline policy
* @return an Http response
*/
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
String authorizationValue = credential.generateAuthorizationHeader(context.getHttpRequest().getUrl(),
context.getHttpRequest().getHeaders().toMap());
context.getHttpRequest().setHeader("Authorization", authorizationValue);
return next.process();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

/** Package containing the inner classes for Azure Tables SDK. */
package com.azure.data.tables;
Loading