|
4 | 4 |
|
5 | 5 | package io.airbyte.config.persistence.split_secrets;
|
6 | 6 |
|
7 |
| -import static org.junit.jupiter.api.Assertions.*; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
8 | 8 |
|
9 | 9 | import com.fasterxml.jackson.databind.JsonNode;
|
10 | 10 | import com.google.common.collect.ImmutableMap;
|
@@ -153,8 +153,98 @@ public class JsonSecretsProcessorTest {
|
153 | 153 | + " }\n"
|
154 | 154 | + " }");
|
155 | 155 |
|
| 156 | + private final static String test = """ |
| 157 | + { |
| 158 | + "provider": { |
| 159 | + "bucket": "bucket", |
| 160 | + "endpoint": "", |
| 161 | + "path_prefix": "", |
| 162 | + "aws_access_key_id": "nothingtosee", |
| 163 | + "aws_secret_access_key": "same" |
| 164 | + } |
| 165 | + } |
| 166 | + """; |
| 167 | + |
| 168 | + private final static String testSpecs = |
| 169 | + """ |
| 170 | + { |
| 171 | + "type": "object", |
| 172 | + "title": "S3 Source Spec", |
| 173 | + "required": [ |
| 174 | + "dataset", |
| 175 | + "path_pattern", |
| 176 | + "provider" |
| 177 | + ], |
| 178 | + "properties": { |
| 179 | + "provider": { |
| 180 | + "type": "object", |
| 181 | + "title": "S3: Amazon Web Services", |
| 182 | + "required": [ |
| 183 | + "bucket" |
| 184 | + ], |
| 185 | + "properties": { |
| 186 | + "bucket": { |
| 187 | + "type": "string", |
| 188 | + "title": "Bucket", |
| 189 | + "description": "Name of the S3 bucket where the file(s) exist." |
| 190 | + }, |
| 191 | + "use_ssl": { |
| 192 | + "type": "boolean", |
| 193 | + "title": "Use Ssl", |
| 194 | + "description": "Is remote server using secure SSL/TLS connection" |
| 195 | + }, |
| 196 | + "endpoint": { |
| 197 | + "type": "string", |
| 198 | + "title": "Endpoint", |
| 199 | + "default": "", |
| 200 | + "description": "Endpoint to an S3 compatible service. Leave empty to use AWS." |
| 201 | + }, |
| 202 | + "path_prefix": { |
| 203 | + "type": "string", |
| 204 | + "title": "Path Prefix", |
| 205 | + "default": "", |
| 206 | + "description": "By providing a path-like prefix (e.g. myFolder/thisTable/) under which all the relevant files sit, we can optimise finding these in S3. This is optional but recommended if your bucket contains many folders/files." |
| 207 | + }, |
| 208 | + "verify_ssl_cert": { |
| 209 | + "type": "boolean", |
| 210 | + "title": "Verify Ssl Cert", |
| 211 | + "description": "Allow self signed certificates" |
| 212 | + }, |
| 213 | + "aws_access_key_id": { |
| 214 | + "type": "string", |
| 215 | + "title": "Aws Access Key Id", |
| 216 | + "description": "In order to access private Buckets stored on AWS S3, this connector requires credentials with the proper permissions. If accessing publicly available data, this field is not necessary.", |
| 217 | + "airbyte_secret": true |
| 218 | + }, |
| 219 | + "aws_secret_access_key": { |
| 220 | + "type": "string", |
| 221 | + "title": "Aws Secret Access Key", |
| 222 | + "description": "In order to access private Buckets stored on AWS S3, this connector requires credentials with the proper permissions. If accessing publicly available data, this field is not necessary.", |
| 223 | + "airbyte_secret": true |
| 224 | + } |
| 225 | + } |
| 226 | + } |
| 227 | + } |
| 228 | + } |
| 229 | + """; |
| 230 | + |
156 | 231 | JsonSecretsProcessor processor = new JsonSecretsProcessor();
|
157 | 232 |
|
| 233 | + @Test |
| 234 | + public void testNestedSecrets() { |
| 235 | + final JsonNode obj = Jsons.deserialize(test); |
| 236 | + final JsonNode specObj = Jsons.deserialize(testSpecs); |
| 237 | + final JsonNode sanitized = processor.maskSecrets(obj, specObj); |
| 238 | + |
| 239 | + final JsonNode expected = Jsons.jsonNode(ImmutableMap.builder() |
| 240 | + .put("bucket", "bucket") |
| 241 | + .put("endpoint", "") |
| 242 | + .put("path_prefix", "") |
| 243 | + .put("aws_access_key_id", JsonSecretsProcessor.SECRETS_MASK) |
| 244 | + .put("aws_secret_access_key", JsonSecretsProcessor.SECRETS_MASK).build()); |
| 245 | + assertEquals(expected, sanitized.get("provider")); |
| 246 | + } |
| 247 | + |
158 | 248 | @Test
|
159 | 249 | public void testMaskSecrets() {
|
160 | 250 | final JsonNode obj = Jsons.jsonNode(ImmutableMap.builder()
|
|
0 commit comments