Skip to content

Commit f7e72cb

Browse files
committed
fix duplicate warning and parameter typo
1 parent c00c55d commit f7e72cb

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

core/src/test/java/cloud/stackit/sdk/core/auth/SetupAuthTest.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
@SuppressWarnings("PMD.TooManyMethods")
3333
@ExtendWith(MockitoExtension.class)
3434
class SetupAuthTest {
35+
36+
private static final String SERVICE_ACCOUNT_KEY_PREFIX = "serviceAccountKey";
37+
private static final String PRIVATE_KEY_PREFIX = "privateKey";
38+
private static final String PRIVATE_KEY_VALUE = "prvKey";
39+
private static final String PRIVATE_KEY_CONTENT = "<my-private-key>";
3540
private static final String JSON_FILE_EXTENSION = ".json";
3641

3742
@Mock private EnvironmentVariables envs;
@@ -98,7 +103,7 @@ void setupKeyFlowReadServiceAccountFromPath() throws IOException {
98103
ServiceAccountKey initSaKey =
99104
createDummyServiceAccount(TestUtils.MOCK_SERVICE_ACCOUNT_PRIVATE_KEY);
100105
String initSaKeyJson = new Gson().toJson(initSaKey);
101-
Path saKeyPath = Files.createTempFile("serviceAccountKey", JSON_FILE_EXTENSION);
106+
Path saKeyPath = Files.createTempFile(SERVICE_ACCOUNT_KEY_PREFIX, JSON_FILE_EXTENSION);
102107
saKeyPath.toFile().deleteOnExit();
103108
Files.write(saKeyPath, initSaKeyJson.getBytes(StandardCharsets.UTF_8));
104109

@@ -148,11 +153,11 @@ void setupKeyFlowReadServiceAccountFromKeyEnv() throws IOException {
148153
@DisplayName("setup key flow - read service account from key path env")
149154
void setupKeyFlowReadServiceAccountFromKeyPathEnv() throws IOException {
150155
// Create service account key
151-
ServiceAccountKey initSaKey = createDummyServiceAccount("privateKey");
156+
ServiceAccountKey initSaKey = createDummyServiceAccount(PRIVATE_KEY_PREFIX);
152157
String keyPathContent = new Gson().toJson(initSaKey);
153158

154159
// Create dummy keyPathFile
155-
Path keyPathFile = Files.createTempFile("serviceAccountKey", JSON_FILE_EXTENSION);
160+
Path keyPathFile = Files.createTempFile(SERVICE_ACCOUNT_KEY_PREFIX, JSON_FILE_EXTENSION);
156161
keyPathFile.toFile().deleteOnExit();
157162
Files.write(keyPathFile, keyPathContent.getBytes(StandardCharsets.UTF_8));
158163

@@ -175,7 +180,7 @@ void setupKeyFlowReadServiceAccountFromPathWithoutPrivateKeyThrowsException()
175180
// Create service account key file
176181
ServiceAccountKey initSaKey = createDummyServiceAccount(null);
177182
String initSaKeyJson = new Gson().toJson(initSaKey);
178-
Path saKeyPath = Files.createTempFile("serviceAccountKey", JSON_FILE_EXTENSION);
183+
Path saKeyPath = Files.createTempFile(SERVICE_ACCOUNT_KEY_PREFIX, JSON_FILE_EXTENSION);
179184
saKeyPath.toFile().deleteOnExit();
180185
Files.write(saKeyPath, initSaKeyJson.getBytes(StandardCharsets.UTF_8));
181186

@@ -212,7 +217,7 @@ void setupKeyFlowReadServiceAccountFromConfigWithoutPrivateKeyThrowsException()
212217
@Test
213218
@DisplayName("load private key - set private key from config")
214219
void loadPrivateKeySetPrivateKeyFromConfig() {
215-
final String prvKey = "prvKey";
220+
final String prvKey = PRIVATE_KEY_VALUE;
216221
ServiceAccountKey saKey = createDummyServiceAccount(null);
217222

218223
CoreConfiguration cfg = new CoreConfiguration().privateKey(prvKey);
@@ -225,7 +230,7 @@ void loadPrivateKeySetPrivateKeyFromConfig() {
225230
@Test
226231
@DisplayName("load private key - does not overwrite existing private key")
227232
void loadPrivateKeyDoesNotOverwriteExistingPrivateKey() {
228-
final String initialPrivateKey = "prvKey";
233+
final String initialPrivateKey = PRIVATE_KEY_VALUE;
229234
final String cfgPrivateKey = "prvKey-updated";
230235

231236
// Create Service Account
@@ -240,10 +245,10 @@ void loadPrivateKeyDoesNotOverwriteExistingPrivateKey() {
240245
@Test
241246
@DisplayName("load private key - set private key path")
242247
void loadPrivateKeySetPrivateKeyPath() throws IOException {
243-
Path tempPrvKeyFile = Files.createTempFile("privateKey", ".pem");
248+
Path tempPrvKeyFile = Files.createTempFile(PRIVATE_KEY_PREFIX, ".pem");
244249
tempPrvKeyFile.toFile().deleteOnExit();
245250

246-
final String privateKeyContent = "<my-private-key>";
251+
final String privateKeyContent = PRIVATE_KEY_CONTENT;
247252
Files.write(tempPrvKeyFile, privateKeyContent.getBytes(StandardCharsets.UTF_8));
248253

249254
// Create Service Account
@@ -260,11 +265,11 @@ void loadPrivateKeySetPrivateKeyPath() throws IOException {
260265
@DisplayName("load private key - set private key path via credentials file")
261266
void loadPrivateKeySetPrivateKeyPathViaCredentialsFile() throws IOException {
262267
// Create privateKeyFile
263-
Path tempPrvKeyFile = Files.createTempFile("privateKey", ".pem");
268+
Path tempPrvKeyFile = Files.createTempFile(PRIVATE_KEY_PREFIX, ".pem");
264269
tempPrvKeyFile.toFile().deleteOnExit();
265270

266271
// Write private key file
267-
final String privateKeyContent = "<my-private-key>";
272+
final String privateKeyContent = PRIVATE_KEY_CONTENT;
268273
Files.write(tempPrvKeyFile, privateKeyContent.getBytes(StandardCharsets.UTF_8));
269274

270275
// Create credentialsFile
@@ -294,7 +299,7 @@ void loadPrivateKeySetPrivateKeyPathViaCredentialsFile() throws IOException {
294299
@Test
295300
@DisplayName("load private key - set private key via credentials file")
296301
void loadPrivateKeySetPrivateKeyViaCredentialsFile() throws IOException {
297-
final String privateKeyContent = "<my-private-key>";
302+
final String privateKeyContent = PRIVATE_KEY_CONTENT;
298303

299304
// Create credentialsFile
300305
Path tempCredentialsFile = Files.createTempFile("credentialsFile", JSON_FILE_EXTENSION);
@@ -322,7 +327,7 @@ void loadPrivateKeySetPrivateKeyViaCredentialsFile() throws IOException {
322327
@Test
323328
@DisplayName("load private key - set private key via env")
324329
void loadPrivateKeySetPrivateKeyViaEnv() {
325-
final String prvKey = "prvKey";
330+
final String prvKey = PRIVATE_KEY_VALUE;
326331
ServiceAccountKey saKey = createDummyServiceAccount(null);
327332
when(envs.getStackitPrivateKey()).thenReturn(prvKey);
328333

@@ -336,9 +341,9 @@ void loadPrivateKeySetPrivateKeyViaEnv() {
336341
@Test
337342
@DisplayName("load private key - set private key path via env")
338343
void loadPrivateKeySetPrivateKeyPathViaEnv() throws IOException {
339-
final String prvKey = "prvKey";
344+
final String prvKey = PRIVATE_KEY_VALUE;
340345
ServiceAccountKey saKey = createDummyServiceAccount(null);
341-
Path tempPrvKeyFile = Files.createTempFile("privateKey", ".pem");
346+
Path tempPrvKeyFile = Files.createTempFile(PRIVATE_KEY_PREFIX, ".pem");
342347
tempPrvKeyFile.toFile().deleteOnExit();
343348
Files.write(tempPrvKeyFile, prvKey.getBytes(StandardCharsets.UTF_8));
344349

@@ -355,7 +360,7 @@ void loadPrivateKeySetPrivateKeyPathViaEnv() throws IOException {
355360
@Test
356361
@DisplayName("load private key - set private key via credentials file in Env")
357362
void loadPrivateKeySetPrivateKeyViaCredentialsFileInEnv() throws IOException {
358-
final String privateKeyContent = "<my-private-key>";
363+
final String privateKeyContent = PRIVATE_KEY_CONTENT;
359364

360365
// Create credentialsFile
361366
Path tempCredentialsFile = Files.createTempFile("credentialsFile", JSON_FILE_EXTENSION);
@@ -410,7 +415,7 @@ void readValueFromCredentialsFileKeyAndKeyPathSetReturnsKeyValue() throws IOExce
410415
String keyPathContent = "keyPath";
411416

412417
// Create dummy keyPathFile
413-
Path keyPathFile = Files.createTempFile("serviceAccountKey", JSON_FILE_EXTENSION);
418+
Path keyPathFile = Files.createTempFile(SERVICE_ACCOUNT_KEY_PREFIX, JSON_FILE_EXTENSION);
414419
keyPathFile.toFile().deleteOnExit();
415420
Files.write(keyPathFile, keyPathContent.getBytes(StandardCharsets.UTF_8));
416421

@@ -457,7 +462,7 @@ void readValueFromCredentialsFileKeySetReturnsKeyValue() throws IOException {
457462
void readValueFromCredentialsFileKeyPathSetReturnsKeyValue() throws IOException {
458463
// Create dummy keyPathFile
459464
String keyPathContent = "keyPath";
460-
Path keyPathFile = Files.createTempFile("serviceAccountKey", JSON_FILE_EXTENSION);
465+
Path keyPathFile = Files.createTempFile(SERVICE_ACCOUNT_KEY_PREFIX, JSON_FILE_EXTENSION);
461466
keyPathFile.toFile().deleteOnExit();
462467
Files.write(keyPathFile, keyPathContent.getBytes(StandardCharsets.UTF_8));
463468

services/iaas/src/main/java/cloud/stackit/sdk/iaas/api/IaasApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public IaasApi() throws IOException {
3333
*
3434
* <p>For production use consider using the constructor with the OkHttpClient parameter.
3535
*
36-
* @param config your STACKIT SDK CoreConfiguration
36+
* @param configuration your STACKIT SDK CoreConfiguration
3737
* @throws IOException
3838
*/
3939
public IaasApi(CoreConfiguration configuration) throws IOException {

0 commit comments

Comments
 (0)