3232import org .apache .drill .test .ClusterFixture ;
3333import org .apache .drill .test .ClusterTest ;
3434import org .apache .hadoop .conf .Configuration ;
35+ import org .junit .AfterClass ;
3536import org .junit .BeforeClass ;
36- import org .junit .ClassRule ;
3737import org .junit .Test ;
38+ import org .testcontainers .DockerClientFactory ;
3839import org .testcontainers .containers .BindMode ;
3940import org .testcontainers .utility .DockerImageName ;
4041import org .testcontainers .vault .VaultContainer ;
4344import java .util .Map ;
4445
4546import static org .junit .Assert .assertEquals ;
47+ import static org .junit .Assume .assumeTrue ;
4648
4749public class CredentialsProviderImplementationsTest extends ClusterTest {
4850
@@ -52,25 +54,32 @@ public class CredentialsProviderImplementationsTest extends ClusterTest {
5254 private static final String USER_SECRET_PATH = "secret/testing/$user" ;
5355 private static final String CONTAINER_POLICY_PATH = "/tmp/read-vault-secrets.hcl" ;
5456
55- @ ClassRule
56- public static final VaultContainer <?> vaultContainer =
57- new VaultContainer <>(DockerImageName .parse ("vault" ).withTag ("1.10.3" ))
58- .withVaultToken (VAULT_ROOT_TOKEN )
59- .withSecretInVault (SHARED_SECRET_PATH ,
60- "top_secret=password1" ,
61- "db_password=dbpassword1" )
62- .withSecretInVault (USER_SECRET_PATH .replace (VaultCredentialsProvider .QUERY_USER_VAR , "alice" ),
63- "top_secret=password1" ,
64- "db_password=dbpassword1" )
65- .withClasspathResourceMapping ("vault/read-vault-secrets.hcl" , CONTAINER_POLICY_PATH , BindMode .READ_ONLY )
66- .withInitCommand (
67- "auth enable approle" ,
68- String .format ("policy write read-secrets %s" , CONTAINER_POLICY_PATH ),
69- String .format ("write %s policies=read-secrets" , VAULT_APP_ROLE_PATH )
70- );
57+ private static VaultContainer <?> vaultContainer ;
7158
7259 @ BeforeClass
7360 public static void init () throws Exception {
61+ assumeTrue (
62+ "Docker is not available, skipping Vault container tests" ,
63+ DockerClientFactory .instance ().isDockerAvailable ()
64+ );
65+
66+ vaultContainer =
67+ new VaultContainer <>(DockerImageName .parse ("vault" ).withTag ("1.10.3" ))
68+ .withVaultToken (VAULT_ROOT_TOKEN )
69+ .withSecretInVault (SHARED_SECRET_PATH ,
70+ "top_secret=password1" ,
71+ "db_password=dbpassword1" )
72+ .withSecretInVault (USER_SECRET_PATH .replace (VaultCredentialsProvider .QUERY_USER_VAR , "alice" ),
73+ "top_secret=password1" ,
74+ "db_password=dbpassword1" )
75+ .withClasspathResourceMapping ("vault/read-vault-secrets.hcl" , CONTAINER_POLICY_PATH , BindMode .READ_ONLY )
76+ .withInitCommand (
77+ "auth enable approle" ,
78+ String .format ("policy write read-secrets %s" , CONTAINER_POLICY_PATH ),
79+ String .format ("write %s policies=read-secrets" , VAULT_APP_ROLE_PATH )
80+ );
81+ vaultContainer .start ();
82+
7483 String vaultAddr = String .format (
7584 "http://%s:%d" ,
7685 vaultContainer .getHost (),
@@ -104,6 +113,13 @@ public static void init() throws Exception {
104113 );
105114 }
106115
116+ @ AfterClass
117+ public static void tearDown () {
118+ if (vaultContainer != null ) {
119+ vaultContainer .stop ();
120+ }
121+ }
122+
107123 @ Test
108124 public void testEnvCredentialsProvider () {
109125 String variableName = "USER" ;
0 commit comments