@kensio/yulin 1.21.19 → 1.21.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,3 +16,28 @@ export declare const simLambdaExecutionCredentials: readonly (readonly [
16
16
  string,
17
17
  string
18
18
  ])[];
19
+ /**
20
+ * The host environment variable names that point an AWS SDK at credentials
21
+ * outside the invocation.
22
+ *
23
+ * A function declaring no variables of its own runs with the host process
24
+ * environment underneath the AWS-provided ones, which is where an in-process
25
+ * handler reads its configuration from. These names are not that
26
+ * configuration. They are how a developer's shell and a CI runner select the
27
+ * AWS access they hold themselves, and real Lambda sets none of them.
28
+ *
29
+ * `AWS_PROFILE` is the one that stops an invocation outright. The Node.js
30
+ * credential provider chain skips its environment-variable provider whenever
31
+ * that name is set, reporting "AWS_PROFILE is set, skipping fromEnv
32
+ * provider.", and the placeholder credentials above go unread. Resolution
33
+ * leaves the simulation for a shared configuration file or an SSO portal, and
34
+ * the client throws while resolving, before the request it was building
35
+ * reaches a simulated service. The rest each name a credential source of their
36
+ * own and are masked for the same reason.
37
+ */
38
+ export declare const hostAwsCredentialVariableNames: ReadonlySet<string>;
39
+ /**
40
+ * The host process variables an invocation keeps, with the ones naming a
41
+ * credential source of the host's own left out.
42
+ */
43
+ export declare function withoutHostAwsCredentialVariables(variables: Record<string, string>): Record<string, string>;
@@ -17,3 +17,48 @@ export const simLambdaExecutionCredentials = [
17
17
  ["AWS_SECRET_ACCESS_KEY", "yulinSimulatedSecretAccessKeyValue000000"],
18
18
  ["AWS_SESSION_TOKEN", "yulin-simulated-session-token"],
19
19
  ];
20
+ /**
21
+ * The host environment variable names that point an AWS SDK at credentials
22
+ * outside the invocation.
23
+ *
24
+ * A function declaring no variables of its own runs with the host process
25
+ * environment underneath the AWS-provided ones, which is where an in-process
26
+ * handler reads its configuration from. These names are not that
27
+ * configuration. They are how a developer's shell and a CI runner select the
28
+ * AWS access they hold themselves, and real Lambda sets none of them.
29
+ *
30
+ * `AWS_PROFILE` is the one that stops an invocation outright. The Node.js
31
+ * credential provider chain skips its environment-variable provider whenever
32
+ * that name is set, reporting "AWS_PROFILE is set, skipping fromEnv
33
+ * provider.", and the placeholder credentials above go unread. Resolution
34
+ * leaves the simulation for a shared configuration file or an SSO portal, and
35
+ * the client throws while resolving, before the request it was building
36
+ * reaches a simulated service. The rest each name a credential source of their
37
+ * own and are masked for the same reason.
38
+ */
39
+ export const hostAwsCredentialVariableNames = new Set([
40
+ "AWS_CONTAINER_AUTHORIZATION_TOKEN",
41
+ "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE",
42
+ "AWS_CONTAINER_CREDENTIALS_FULL_URI",
43
+ "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",
44
+ "AWS_CONFIG_FILE",
45
+ "AWS_DEFAULT_PROFILE",
46
+ "AWS_PROFILE",
47
+ "AWS_ROLE_ARN",
48
+ "AWS_ROLE_SESSION_NAME",
49
+ "AWS_SHARED_CREDENTIALS_FILE",
50
+ "AWS_WEB_IDENTITY_TOKEN_FILE",
51
+ ]);
52
+ /**
53
+ * The host process variables an invocation keeps, with the ones naming a
54
+ * credential source of the host's own left out.
55
+ */
56
+ export function withoutHostAwsCredentialVariables(variables) {
57
+ const kept = [];
58
+ for (const [name, value] of Object.entries(variables)) {
59
+ if (!hostAwsCredentialVariableNames.has(name)) {
60
+ kept.push([name, value]);
61
+ }
62
+ }
63
+ return Object.fromEntries(kept);
64
+ }
@@ -6,6 +6,11 @@
6
6
  * merged once, so a variable the test process sets between two invocations
7
7
  * reaches the second of them.
8
8
  *
9
+ * The host's own AWS credential variables are left out. An invocation is
10
+ * attributed to the function's execution Role, and a name pointing an SDK at
11
+ * the credentials of whoever started the test process would make the
12
+ * invocation depend on them. See `hostAwsCredentialVariableNames`.
13
+ *
9
14
  * What the handler itself wrote is kept and laid over both, which is the warm
10
15
  * execution environment semantics a function declaring variables gets from
11
16
  * reusing one object. A name the handler wrote and the host also sets is the
@@ -1,4 +1,5 @@
1
1
  import { simProcessEnvironment } from "../../../../util/process/sim-process-environment.js";
2
+ import { withoutHostAwsCredentialVariables } from "./sim-lambda-execution-credentials.js";
2
3
  /**
3
4
  * The environment of a function that declares no variables of its own.
4
5
  *
@@ -7,6 +8,11 @@ import { simProcessEnvironment } from "../../../../util/process/sim-process-envi
7
8
  * merged once, so a variable the test process sets between two invocations
8
9
  * reaches the second of them.
9
10
  *
11
+ * The host's own AWS credential variables are left out. An invocation is
12
+ * attributed to the function's execution Role, and a name pointing an SDK at
13
+ * the credentials of whoever started the test process would make the
14
+ * invocation depend on them. See `hostAwsCredentialVariableNames`.
15
+ *
10
16
  * What the handler itself wrote is kept and laid over both, which is the warm
11
17
  * execution environment semantics a function declaring variables gets from
12
18
  * reusing one object. A name the handler wrote and the host also sets is the
@@ -19,7 +25,7 @@ export class SimLambdaHostBackedVariables {
19
25
  */
20
26
  async runWith(functionVariables, run) {
21
27
  const merged = {
22
- ...simProcessEnvironment.definedHostVariables(),
28
+ ...withoutHostAwsCredentialVariables(simProcessEnvironment.definedHostVariables()),
23
29
  ...functionVariables,
24
30
  ...Object.fromEntries(this.written),
25
31
  };
@@ -3158,6 +3158,16 @@ that is where such a handler's configuration comes from when nothing declares it
3158
3158
  variables on the function keeps the test explicit about where they came from. Zip-packaged code in
3159
3159
  the vm runtime gets the function's own variables either way, and never the test process's.
3160
3160
 
3161
+ One group of host variables is masked whatever the function declares. `AWS_PROFILE`,
3162
+ `AWS_DEFAULT_PROFILE`, `AWS_CONFIG_FILE`, `AWS_SHARED_CREDENTIALS_FILE`,
3163
+ `AWS_WEB_IDENTITY_TOKEN_FILE`, `AWS_ROLE_ARN`, `AWS_ROLE_SESSION_NAME` and the
3164
+ `AWS_CONTAINER_CREDENTIALS_*` and `AWS_CONTAINER_AUTHORIZATION_*` names go unset for the length of
3165
+ an invocation. Each of them points an AWS SDK at credentials held by whoever started the test
3166
+ process, and a client built in a handler follows one straight out of the simulation. `AWS_PROFILE`
3167
+ does that even with the placeholder credentials above in place, because the Node.js credential
3168
+ provider chain skips its environment-variable provider whenever a profile is named. Masking them
3169
+ keeps a test independent of the machine running it, and real Lambda sets none of them anyway.
3170
+
3161
3171
  This is also how a function reaches something outside the simulation, such as a Redis or a
3162
3172
  Postgres. See [non-AWS dependencies](https://yulinsim.dev/non-aws-dependencies/).
3163
3173
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kensio/yulin",
3
- "version": "1.21.19",
3
+ "version": "1.21.20",
4
4
  "description": "AWS system behaviour simulation for isolated unit testing",
5
5
  "repository": "https://github.com/KensioSoftware/yulin",
6
6
  "homepage": "https://yulinsim.dev/",