Skip to content

Commit

Permalink
Merge branch 'databrickslabs:master' into fix/888
Browse files Browse the repository at this point in the history
  • Loading branch information
tylangesmith authored Nov 3, 2021
2 parents 67b0355 + 605dae3 commit 9ce8d74
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 126 deletions.
25 changes: 14 additions & 11 deletions common/azure_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ func TestGetJWTProperty_AzureCLI_SP(t *testing.T) {
os.Setenv("PATH", "testdata:/bin")

aa := DatabricksClient{
AzureClientID: "a",
AzureClientSecret: "b",
AzureTenantID: "c",
AzureDatabricksResourceID: "/subscriptions/a/resourceGroups/b/providers/Microsoft.Databricks/workspaces/c",
AzureClientID: "a",
AzureClientSecret: "b",
AzureTenantID: "c",
Host: "https://adb-1232.azuredatabricks.net",
}
tid, err := aa.GetAzureJwtProperty("tid")
assert.NoError(t, err)
Expand Down Expand Up @@ -434,16 +434,15 @@ func TestGetJWTProperty_AzureCli_Error(t *testing.T) {
}`)
defer server.Close()

client.AzureDatabricksResourceID = "/subscriptions/a/resourceGroups/b/providers/Microsoft.Databricks/workspaces/c"
client.Host = "https://adb-1232.azuredatabricks.net"

_, err := client.GetAzureJwtProperty("tid")
require.EqualError(t, err, "unexpected end of JSON input")
}

func setupJwtTestClient() (*httptest.Server, *DatabricksClient) {
client := DatabricksClient{InsecureSkipVerify: true,
AzureDatabricksResourceID: "/subscriptions/a/resourceGroups/b/providers/Microsoft.Databricks/workspaces/c",
Host: "https://adb-1232.azuredatabricks.net",
Host: "https://adb-1232.azuredatabricks.net",
}
ctx := context.Background()

Expand All @@ -469,7 +468,8 @@ func setupJwtTestClient() (*httptest.Server, *DatabricksClient) {

func TestGetJWTProperty_AzureCli(t *testing.T) {
defer CleanupEnvironment()()
os.Setenv("PATH", "testdata/az-good-token:/bin")
os.Setenv("PATH", "testdata:/bin")
os.Setenv("TF_AAD_TOKEN", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2MzU2OTU4MzksImV4cCI6MTY2NzIzMTgzOSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsInRpZCI6ImFiYyJ9._G1DrR4DspidISpsra8UnecV_FV4zMlJDtSNzaS0UxI")

srv, client := setupJwtTestClient()
assert.NotNil(t, srv)
Expand All @@ -483,7 +483,8 @@ func TestGetJWTProperty_AzureCli(t *testing.T) {

func TestGetJWTProperty_AzureCli_Error_DB_PAT(t *testing.T) {
defer CleanupEnvironment()()
os.Setenv("PATH", "testdata/az-bad-token1:/bin")
os.Setenv("PATH", "testdata:/bin")
os.Setenv("TF_AAD_TOKEN", "dapi123")

srv, client := setupJwtTestClient()
assert.NotNil(t, srv)
Expand All @@ -496,7 +497,8 @@ func TestGetJWTProperty_AzureCli_Error_DB_PAT(t *testing.T) {

func TestGetJWTProperty_AzureCli_Error_No_TenantID(t *testing.T) {
defer CleanupEnvironment()()
os.Setenv("PATH", "testdata/az-bad-token2:/bin")
os.Setenv("PATH", "testdata:/bin")
os.Setenv("TF_AAD_TOKEN", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2MzU3OTMwOTksImV4cCI6MTY2NzMyOTA5OSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSJ9.bWKxWSNburEQPGx71pxO1xTa8cuGue5PeXn407voUMI")

srv, client := setupJwtTestClient()
assert.NotNil(t, srv)
Expand All @@ -509,7 +511,8 @@ func TestGetJWTProperty_AzureCli_Error_No_TenantID(t *testing.T) {

func TestGetJWTProperty_AzureCli_Error_EmptyToken(t *testing.T) {
defer CleanupEnvironment()()
os.Setenv("PATH", "testdata/az-bad-token3:/bin")
os.Setenv("PATH", "testdata:/bin")
os.Setenv("TF_AAD_TOKEN", " ")

srv, client := setupJwtTestClient()
assert.NotNil(t, srv)
Expand Down
10 changes: 7 additions & 3 deletions common/testdata/az
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ fi

# Macos
EXP="$(/bin/date -v+${EXPIRE:=10S} +'%F %T' 2>/dev/null)"
if [ "" = "${EXP}" ]; then
if [ -z "${EXP}" ]; then
# Linux
EXPIRE=$(/bin/echo $EXPIRE | /bin/sed 's/S/seconds/')
EXPIRE=$(/bin/echo $EXPIRE | /bin/sed 's/M/minutes/')
EXP=$(/bin/date --date=+${EXPIRE:=10seconds} +'%FT%TZ')
fi

if [ -z "${TF_AAD_TOKEN}" ]; then
TF_AAD_TOKEN="..."
fi

/bin/echo "{
\"accessToken\": \"...\",
\"accessToken\": \"${TF_AAD_TOKEN}\",
\"expiresOn\": \"${EXP}\",
\"subscription\": \"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\",
\"tenant\": \"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\",
\"tokenType\": \"Bearer\"
}"
}"
28 changes: 0 additions & 28 deletions common/testdata/az-bad-token1/az

This file was deleted.

28 changes: 0 additions & 28 deletions common/testdata/az-bad-token2/az

This file was deleted.

28 changes: 0 additions & 28 deletions common/testdata/az-bad-token3/az

This file was deleted.

28 changes: 0 additions & 28 deletions common/testdata/az-good-token/az

This file was deleted.

0 comments on commit 9ce8d74

Please sign in to comment.