|
| 1 | +const { configureEnvironment, EnvironmentMisconfigurationError } = require("../src"); |
| 2 | + |
| 3 | +describe("configureEnvironment", () => { |
| 4 | + test("empty environment", () => { |
| 5 | + const env = {}; |
| 6 | + const allowListStr = ""; |
| 7 | + configureEnvironment(env, allowListStr); |
| 8 | + expect(env).toEqual({ |
| 9 | + AWS_ACCESS_KEY_ID: "test", |
| 10 | + AWS_SECRET_ACCESS_KEY: "test", |
| 11 | + AWS_REGION: "us-east-1", |
| 12 | + AWS_DEFAULT_REGION: "us-east-1", |
| 13 | + AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566", |
| 14 | + AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566", |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + test("custom endpoint url", () => { |
| 19 | + const env = { |
| 20 | + AWS_ENDPOINT_URL: "http://foo.bar:4567", |
| 21 | + AWS_ENDPOINT_URL_S3: "http://foo.bar:4567", |
| 22 | + }; |
| 23 | + const allowListStr = ""; |
| 24 | + configureEnvironment(env, allowListStr); |
| 25 | + expect(env).toEqual({ |
| 26 | + AWS_ACCESS_KEY_ID: "test", |
| 27 | + AWS_SECRET_ACCESS_KEY: "test", |
| 28 | + AWS_REGION: "us-east-1", |
| 29 | + AWS_DEFAULT_REGION: "us-east-1", |
| 30 | + AWS_ENDPOINT_URL: "http://foo.bar:4567", |
| 31 | + AWS_ENDPOINT_URL_S3: "http://foo.bar:4567", |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + test("custom endpoint url without specifying s3 url", () => { |
| 36 | + const env = { |
| 37 | + AWS_ENDPOINT_URL: "http://foo.bar:4567", |
| 38 | + }; |
| 39 | + const allowListStr = ""; |
| 40 | + expect(() => configureEnvironment(env, allowListStr)).toThrow(EnvironmentMisconfigurationError); |
| 41 | + }); |
| 42 | + |
| 43 | + test("strip extra configuration envars", () => { |
| 44 | + const env = { |
| 45 | + AWS_PROFILE: "my-profile", |
| 46 | + }; |
| 47 | + const allowListStr = ""; |
| 48 | + configureEnvironment(env, allowListStr); |
| 49 | + expect(env).toEqual({ |
| 50 | + AWS_ACCESS_KEY_ID: "test", |
| 51 | + AWS_SECRET_ACCESS_KEY: "test", |
| 52 | + AWS_REGION: "us-east-1", |
| 53 | + AWS_DEFAULT_REGION: "us-east-1", |
| 54 | + AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566", |
| 55 | + AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566", |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + test("allowlist of profile", () => { |
| 60 | + const env = { |
| 61 | + AWS_PROFILE: "my-profile", |
| 62 | + }; |
| 63 | + const allowListStr = "AWS_PROFILE"; |
| 64 | + configureEnvironment(env, allowListStr); |
| 65 | + expect(env).toEqual({ |
| 66 | + AWS_ACCESS_KEY_ID: "test", |
| 67 | + AWS_SECRET_ACCESS_KEY: "test", |
| 68 | + AWS_PROFILE: "my-profile", |
| 69 | + AWS_REGION: "us-east-1", |
| 70 | + AWS_DEFAULT_REGION: "us-east-1", |
| 71 | + AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566", |
| 72 | + AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566", |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + test("credentials overriding", () => { |
| 77 | + const env = { |
| 78 | + AWS_ACCESS_KEY_ID: "something", |
| 79 | + AWS_SECRET_ACCESS_KEY: "else", |
| 80 | + }; |
| 81 | + const allowListStr = "AWS_PROFILE,AWS_SECRET_ACCESS_KEY,AWS_ACCESS_KEY_ID"; |
| 82 | + configureEnvironment(env, allowListStr); |
| 83 | + expect(env).toEqual({ |
| 84 | + AWS_ACCESS_KEY_ID: "something", |
| 85 | + AWS_SECRET_ACCESS_KEY: "else", |
| 86 | + AWS_REGION: "us-east-1", |
| 87 | + AWS_DEFAULT_REGION: "us-east-1", |
| 88 | + AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566", |
| 89 | + AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566", |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | + test("region overriding", () => { |
| 94 | + const env = { |
| 95 | + AWS_REGION: "eu-central-1", |
| 96 | + AWS_DEFAULT_REGION: "eu-central-1", |
| 97 | + }; |
| 98 | + const allowListStr = "AWS_REGION,AWS_DEFAULT_REGION"; |
| 99 | + configureEnvironment(env, allowListStr); |
| 100 | + expect(env).toEqual({ |
| 101 | + AWS_ACCESS_KEY_ID: "test", |
| 102 | + AWS_SECRET_ACCESS_KEY: "test", |
| 103 | + AWS_REGION: "eu-central-1", |
| 104 | + AWS_DEFAULT_REGION: "eu-central-1", |
| 105 | + AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566", |
| 106 | + AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566", |
| 107 | + }); |
| 108 | + }); |
| 109 | +}); |
0 commit comments