-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGCPAuthIntegrationTest.java
More file actions
59 lines (44 loc) · 1.97 KB
/
GCPAuthIntegrationTest.java
File metadata and controls
59 lines (44 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.infisical.sdk.auth;
import com.infisical.sdk.InfisicalSdk;
import com.infisical.sdk.config.SdkConfig;
import com.infisical.sdk.util.EnvironmentVariables;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.*;
public class GCPAuthIntegrationTest {
private static final Logger logger = LoggerFactory.getLogger(GCPAuthIntegrationTest.class);
@Test
public void testGCPAuthAndFetchSecrets() {
try {
// Load env variables
var envVars = new EnvironmentVariables();
// Get Machine Identity Id
String machineIdentityId = System.getenv("INFISICAL_MACHINE_IDENTITY_ID");
// Check if env variable machine identity is set, others are already tested via env tests
assertNotNull(machineIdentityId, "INFISICAL_MACHINE_IDENTITY_ID env variable must be set");
assertFalse(machineIdentityId.isEmpty(), "INFISICAL_MACHINE_IDENTITY_ID env variable must not be empty");
// Create SDK instance
var sdk = new InfisicalSdk(new SdkConfig.Builder()
.withSiteUrl(envVars.getSiteUrl())
.build()
);
// Authenticate using GCP Auth
assertDoesNotThrow(() -> {
sdk.Auth().GCPAuthLogin(machineIdentityId);
});
// Test if we have correctly logged in and we can list the secrets
var secrets = sdk.Secrets().ListSecrets(
envVars.getProjectId(),
"dev",
"/",
null,
null,
null);
logger.info("TestGCPAuth Successful");
logger.info("Secrets length : {}", secrets.size());
} catch (Exception e) {
throw new AssertionError(e);
}
}
}