Skip to content

Commit

Permalink
Add test for Azure OAuth file system configuration
Browse files Browse the repository at this point in the history
Co-authored-by: Marius Grama <findinpath@gmail.com>
  • Loading branch information
2 people authored and dain committed Mar 5, 2024
1 parent 63f5155 commit 94529b9
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,15 @@ jobs:
ABFS_FLAT_ACCESS_KEY: todo
ABFS_HIERARCHICAL_ACCOUNT: todo
ABFS_HIERARCHICAL_ACCESS_KEY: todo
ABFS_OAUTH_TENANT_ID: todo
ABFS_OAUTH_CLIENT_ID: todo
ABFS_OAUTH_CLIENT_SECRET: todo
# todo(https://github.com/trinodb/trino/issues/18998) Enable when we have env variables in place
# Run tests only if any of the secrets are present
if: >-
false &&
contains(matrix.modules, 'trino-filesystem-azure') && contains(matrix.profile, 'cloud-tests') &&
(env.CI_SKIP_SECRETS_PRESENCE_CHECKS != '' || env.ABFS_FLAT_ACCESS_KEY != '' || env.ABFS_HIERARCHICAL_ACCESS_KEY != '')
(env.CI_SKIP_SECRETS_PRESENCE_CHECKS != '' || env.ABFS_FLAT_ACCESS_KEY != '' || env.ABFS_HIERARCHICAL_ACCESS_KEY != '' || env.ABFS_OAUTH_CLIENT_SECRET != '')
run: |
$MAVEN test ${MAVEN_TEST} -pl ${{ matrix.modules }} ${{ format('-P {0}', matrix.profile) }}
- name: GCS FileSystem Cloud Tests
Expand Down
4 changes: 4 additions & 0 deletions lib/trino-filesystem-azure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@
<excludes>
<exclude>**/TestAzureFileSystemGen2Flat.java</exclude>
<exclude>**/TestAzureFileSystemGen2Hierarchical.java</exclude>
<exclude>**/TestAzureFileSystemOAuthGen2Flat.java</exclude>
<exclude>**/TestAzureFileSystemOAuthGen2Hierarchical.java</exclude>
</excludes>
</configuration>
</plugin>
Expand All @@ -207,6 +209,8 @@
<includes>
<include>**/TestAzureFileSystemGen2Flat.java</include>
<include>**/TestAzureFileSystemGen2Hierarchical.java</include>
<include>**/TestAzureFileSystemOAuthGen2Flat.java</include>
<include>**/TestAzureFileSystemOAuthGen2Hierarchical.java</include>
</includes>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ protected void initializeWithAccessKey(String account, String accountKey, Accoun
initialize(account, new AzureAuthAccessKey(accountKey), accountKind);
}

protected void initializeWithOAuth(String account, String tenantId, String clientId, String clientSecret, AccountKind accountKind)
throws IOException
{
String clientEndpoint = "https://login.microsoftonline.com/%s/oauth2/v2.0/token".formatted(tenantId);
initialize(account, new AzureAuthOauth(clientEndpoint, tenantId, clientId, clientSecret), accountKind);
}

private void initialize(String account, AzureAuth azureAuth, AccountKind accountKind)
throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.filesystem.azure;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;

import java.io.IOException;

import static io.trino.filesystem.azure.AbstractTestAzureFileSystem.AccountKind.FLAT;

@TestInstance(Lifecycle.PER_CLASS)
public class TestAzureFileSystemOAuthGen2Flat
extends AbstractTestAzureFileSystem
{
@BeforeAll
void setup()
throws IOException
{
String account = getRequiredEnvironmentVariable("ABFS_FLAT_ACCOUNT");
String tenantId = getRequiredEnvironmentVariable("ABFS_OAUTH_TENANT_ID");
String clientId = getRequiredEnvironmentVariable("ABFS_OAUTH_CLIENT_ID");
String clientSecret = getRequiredEnvironmentVariable("ABFS_OAUTH_CLIENT_SECRET");
initializeWithOAuth(account, tenantId, clientId, clientSecret, FLAT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.filesystem.azure;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;

import java.io.IOException;

import static io.trino.filesystem.azure.AbstractTestAzureFileSystem.AccountKind.HIERARCHICAL;

@TestInstance(Lifecycle.PER_CLASS)
public class TestAzureFileSystemOAuthGen2Hierarchical
extends AbstractTestAzureFileSystem
{
@BeforeAll
void setup()
throws IOException
{
String account = getRequiredEnvironmentVariable("ABFS_HIERARCHICAL_ACCOUNT");
String tenantId = getRequiredEnvironmentVariable("ABFS_OAUTH_TENANT_ID");
String clientId = getRequiredEnvironmentVariable("ABFS_OAUTH_CLIENT_ID");
String clientSecret = getRequiredEnvironmentVariable("ABFS_OAUTH_CLIENT_SECRET");
initializeWithOAuth(account, tenantId, clientId, clientSecret, HIERARCHICAL);
}
}

0 comments on commit 94529b9

Please sign in to comment.