|
1 | 1 | package com.checkmarx.ast; |
2 | 2 |
|
3 | 3 | import com.checkmarx.ast.wrapper.CxConfig; |
| 4 | +import com.checkmarx.ast.wrapper.CxConfig.InvalidCLIConfigException; |
4 | 5 | import com.checkmarx.ast.wrapper.CxConstants; |
5 | 6 | import org.junit.jupiter.api.Assertions; |
6 | 7 | import org.junit.jupiter.api.Test; |
7 | 8 |
|
8 | | -import java.util.Arrays; |
9 | 9 | import java.util.List; |
10 | 10 |
|
11 | 11 | class CxConfigTest extends BaseTest { |
12 | 12 |
|
13 | 13 | @Test |
14 | | - void testConfig_WhenUsingApiKey_GeneratesCorrectArguments() { |
15 | | - // Arrange |
| 14 | + void testApiKeyAuthentication() { |
16 | 15 | CxConfig config = CxConfig.builder() |
17 | 16 | .apiKey("test-api-key") |
18 | | - .tenant("test-tenant") |
19 | | - .baseUri("https://test.checkmarx.com") |
20 | 17 | .build(); |
21 | | - |
22 | | - // Act |
| 18 | + |
23 | 19 | List<String> arguments = config.toArguments(); |
| 20 | + Assertions.assertTrue(arguments.contains(CxConstants.API_KEY)); |
| 21 | + Assertions.assertTrue(arguments.contains("test-api-key")); |
| 22 | + } |
24 | 23 |
|
25 | | - // Assert |
26 | | - Assertions.assertTrue(arguments.contains(CxConstants.API_KEY), "Should contain API_KEY argument"); |
27 | | - Assertions.assertTrue(arguments.contains("test-api-key"), "Should contain API key value"); |
28 | | - Assertions.assertTrue(arguments.contains(CxConstants.TENANT), "Should contain TENANT argument"); |
29 | | - Assertions.assertTrue(arguments.contains("test-tenant"), "Should contain tenant value"); |
30 | | - Assertions.assertTrue(arguments.contains(CxConstants.BASE_URI), "Should contain BASE_URI argument"); |
31 | | - Assertions.assertTrue(arguments.contains("https://test.checkmarx.com"), "Should contain base URI value"); |
| 24 | + @Test |
| 25 | + void testClientIdSecretAuthentication() { |
| 26 | + CxConfig config = CxConfig.builder() |
| 27 | + .clientId("test-client-id") |
| 28 | + .clientSecret("test-client-secret") |
| 29 | + .build(); |
| 30 | + |
| 31 | + List<String> arguments = config.toArguments(); |
| 32 | + Assertions.assertTrue(arguments.contains(CxConstants.CLIENT_ID)); |
| 33 | + Assertions.assertTrue(arguments.contains("test-client-id")); |
| 34 | + Assertions.assertTrue(arguments.contains(CxConstants.CLIENT_SECRET)); |
| 35 | + Assertions.assertTrue(arguments.contains("test-client-secret")); |
32 | 36 | } |
33 | 37 |
|
34 | 38 | @Test |
35 | | - void testConfig_WhenUsingClientCredentials_GeneratesCorrectArguments() { |
36 | | - // Arrange |
| 39 | + void testTenantAndBaseUris() { |
37 | 40 | CxConfig config = CxConfig.builder() |
38 | | - .clientId("test-client") |
39 | | - .clientSecret("test-secret") |
40 | 41 | .tenant("test-tenant") |
| 42 | + .baseUri("https://example.com") |
| 43 | + .baseAuthUri("https://auth.example.com") |
41 | 44 | .build(); |
42 | | - |
43 | | - // Act |
| 45 | + |
44 | 46 | List<String> arguments = config.toArguments(); |
45 | | - |
46 | | - // Assert |
47 | | - Assertions.assertTrue(arguments.contains(CxConstants.CLIENT_ID), "Should contain CLIENT_ID argument"); |
48 | | - Assertions.assertTrue(arguments.contains("test-client"), "Should contain client ID value"); |
49 | | - Assertions.assertTrue(arguments.contains(CxConstants.CLIENT_SECRET), "Should contain CLIENT_SECRET argument"); |
50 | | - Assertions.assertTrue(arguments.contains("test-secret"), "Should contain client secret value"); |
51 | | - Assertions.assertTrue(arguments.contains(CxConstants.TENANT), "Should contain TENANT argument"); |
52 | | - Assertions.assertTrue(arguments.contains("test-tenant"), "Should contain tenant value"); |
| 47 | + Assertions.assertTrue(arguments.contains(CxConstants.TENANT)); |
| 48 | + Assertions.assertTrue(arguments.contains("test-tenant")); |
| 49 | + Assertions.assertTrue(arguments.contains(CxConstants.BASE_URI)); |
| 50 | + Assertions.assertTrue(arguments.contains("https://example.com")); |
| 51 | + Assertions.assertTrue(arguments.contains(CxConstants.BASE_AUTH_URI)); |
| 52 | + Assertions.assertTrue(arguments.contains("https://auth.example.com")); |
53 | 53 | } |
54 | 54 |
|
55 | 55 | @Test |
56 | | - void testConfig_WhenSettingAdditionalParameters_ParsesCorrectly() { |
57 | | - // Arrange |
| 56 | + void testEmptyConfig() { |
58 | 57 | CxConfig config = CxConfig.builder().build(); |
59 | | - String params = "--param1 value1 --param2 \"value 2\""; |
60 | | - |
61 | | - // Act |
62 | | - config.setAdditionalParameters(params); |
63 | | - List<String> additionalParams = config.getAdditionalParameters(); |
64 | | - |
65 | | - // Assert |
66 | | - List<String> expected = Arrays.asList("--param1", "value1", "--param2", "value 2"); |
67 | | - Assertions.assertEquals(expected, additionalParams, "Additional parameters should be parsed correctly"); |
| 58 | + |
| 59 | + List<String> arguments = config.toArguments(); |
| 60 | + Assertions.assertTrue(arguments.isEmpty()); |
68 | 61 | } |
69 | 62 |
|
70 | 63 | @Test |
71 | | - void testConfig_WhenNoAuthProvided_GeneratesMinimalArguments() { |
72 | | - // Arrange |
| 64 | + void testAdditionalParametersParsing() { |
73 | 65 | CxConfig config = CxConfig.builder() |
74 | | - .tenant("test-tenant") |
| 66 | + .additionalParameters("--debug --verbose \"multi word value\"") |
75 | 67 | .build(); |
| 68 | + |
| 69 | + List<String> arguments = config.getAdditionalParameters(); |
| 70 | + Assertions.assertEquals(3, arguments.size()); |
| 71 | + Assertions.assertTrue(arguments.contains("--debug")); |
| 72 | + Assertions.assertTrue(arguments.contains("--verbose")); |
| 73 | + Assertions.assertTrue(arguments.contains("multi word value")); |
| 74 | + } |
76 | 75 |
|
77 | | - // Act |
78 | | - List<String> arguments = config.toArguments(); |
| 76 | + @Test |
| 77 | + void testSpecialCharactersInAdditionalParameters() { |
| 78 | + CxConfig config = CxConfig.builder() |
| 79 | + .additionalParameters("--path \"C:\\Program Files\\Tool\"") |
| 80 | + .build(); |
| 81 | + |
| 82 | + List<String> arguments = config.getAdditionalParameters(); |
| 83 | + Assertions.assertEquals(1, arguments.size()); |
| 84 | + Assertions.assertTrue(arguments.contains("C:\\Program Files\\Tool")); |
| 85 | + } |
79 | 86 |
|
80 | | - // Assert |
81 | | - Assertions.assertTrue(arguments.contains(CxConstants.TENANT), "Should contain TENANT argument"); |
82 | | - Assertions.assertTrue(arguments.contains("test-tenant"), "Should contain tenant value"); |
83 | | - Assertions.assertFalse(arguments.contains(CxConstants.API_KEY), "Should not contain API_KEY argument"); |
84 | | - Assertions.assertFalse(arguments.contains(CxConstants.CLIENT_ID), "Should not contain CLIENT_ID argument"); |
| 87 | + @Test |
| 88 | + void testInvalidCLIConfigException() { |
| 89 | + Assertions.assertThrows(InvalidCLIConfigException.class, () -> { |
| 90 | + throw new InvalidCLIConfigException("Invalid configuration"); |
| 91 | + }); |
85 | 92 | } |
86 | 93 | } |
0 commit comments