Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ import { CredentialsProviderFactory } from "./credentials_provider_factory";
import { AssumeRoleWithSAMLCommand, STSClient } from "@aws-sdk/client-sts";
import { WrapperProperties } from "../../wrapper_property";

import pkgAwsSdk from "aws-sdk";
const { Credentials } = pkgAwsSdk;

import { AwsWrapperError } from "../../utils/errors";
import { AwsCredentialIdentityProvider, AwsCredentialIdentity } from "@smithy/types/dist-types/identity/awsCredentialIdentity";
import { AwsCredentialIdentity, AwsCredentialIdentityProvider } from "@smithy/types/dist-types/identity/awsCredentialIdentity";
import { decode } from "entities";

export abstract class SamlCredentialsProviderFactory implements CredentialsProviderFactory {
Expand All @@ -46,11 +43,11 @@ export abstract class SamlCredentialsProviderFactory implements CredentialsProvi
const credentials = results["Credentials"];

if (credentials && credentials.AccessKeyId && credentials.SecretAccessKey && credentials.SessionToken) {
return new Credentials({
return {
accessKeyId: credentials.AccessKeyId,
secretAccessKey: credentials.SecretAccessKey,
sessionToken: credentials.SessionToken
});
};
}
throw new AwsWrapperError("Credentials from SAML request not found");
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"@types/pg": "^8.11.10",
"@types/tough-cookie": "^4.0.5",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"aws-sdk": "^2.1691.0",
"aws-xray-sdk": "^3.10.1",
"axios": "^1.7.7",
"axios-cookiejar-support": "^5.0.3",
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/federated_auth_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import { anything, instance, mock, spy, verify, when } from "ts-mockito";
import { CredentialsProviderFactory } from "../../common/lib/plugins/federated_auth/credentials_provider_factory";
import { DatabaseDialect } from "../../common/lib/database_dialect/database_dialect";

import pkgAwsSdk from "aws-sdk";
const { Credentials } = pkgAwsSdk;

import { HostRole } from "../../common/lib/host_role";
import { NullTelemetryFactory } from "../../common/lib/utils/telemetry/null_telemetry_factory";
import { jest } from "@jest/globals";
Expand All @@ -48,7 +45,11 @@ const mockDialectInstance = instance(mockDialect);
const mockPluginService = mock(PluginService);
const mockCredentialsProviderFactory = mock<CredentialsProviderFactory>();
const spyIamUtils = spy(IamAuthUtils);
const mockCredentials = mock(Credentials);
const testCredentials = {
accessKeyId: "foo",
secretAccessKey: "bar",
sessionToken: "baz"
};
const mockConnectFunc = jest.fn(() => {
return Promise.resolve(mock(PgClientWrapper));
});
Expand All @@ -61,7 +62,7 @@ describe("federatedAuthTest", () => {
when(mockPluginService.getDialect()).thenReturn(mockDialectInstance);
when(mockPluginService.getTelemetryFactory()).thenReturn(new NullTelemetryFactory());
when(mockDialect.getDefaultPort()).thenReturn(defaultPort);
when(mockCredentialsProviderFactory.getAwsCredentialsProvider(anything(), anything(), anything())).thenResolve(instance(mockCredentials));
when(mockCredentialsProviderFactory.getAwsCredentialsProvider(anything(), anything(), anything())).thenResolve(instance(testCredentials));
props = new Map<string, any>();
WrapperProperties.PLUGINS.set(props, "federatedAuth");
WrapperProperties.DB_USER.set(props, dbUser);
Expand Down
17 changes: 9 additions & 8 deletions tests/unit/okta_auth_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import { HostInfo } from "../../common/lib/host_info";
import { WrapperProperties } from "../../common/lib/wrapper_property";
import { DatabaseDialect } from "../../common/lib/database_dialect/database_dialect";

import pkgAwsSdk from "aws-sdk";
const { Credentials } = pkgAwsSdk;

import { OktaAuthPlugin } from "../../common/lib/plugins/federated_auth/okta_auth_plugin";
import { NullTelemetryFactory } from "../../common/lib/utils/telemetry/null_telemetry_factory";
import { jest } from "@jest/globals";
Expand All @@ -42,7 +39,11 @@ const testTokenInfo = new TokenInfo(testToken, Date.now() + 300000);
const mockPluginService = mock(PluginService);
const mockDialect = mock<DatabaseDialect>();
const mockDialectInstance = instance(mockDialect);
const mockCredentials = mock(Credentials);
const testCredentials = {
accessKeyId: "foo",
secretAccessKey: "bar",
sessionToken: "baz"
};
const spyIamUtils = spy(IamAuthUtils);
const mockCredentialsProviderFactory = mock<CredentialsProviderFactory>();
const mockConnectFunc = jest.fn(() => {
Expand All @@ -57,7 +58,7 @@ describe("oktaAuthTest", () => {
when(mockPluginService.getDialect()).thenReturn(mockDialectInstance);
when(mockPluginService.getTelemetryFactory()).thenReturn(new NullTelemetryFactory());
when(mockDialect.getDefaultPort()).thenReturn(defaultPort);
when(mockCredentialsProviderFactory.getAwsCredentialsProvider(anything(), anything(), anything())).thenResolve(mockCredentials);
when(mockCredentialsProviderFactory.getAwsCredentialsProvider(anything(), anything(), anything())).thenResolve(testCredentials);
props = new Map<string, any>();
WrapperProperties.PLUGINS.set(props, "okta");
WrapperProperties.DB_USER.set(props, dbUser);
Expand Down Expand Up @@ -94,7 +95,7 @@ describe("oktaAuthTest", () => {
await spyPluginInstance.connect(hostInfo, props, false, mockConnectFunc);

verify(
spyIamUtils.generateAuthenticationToken(hostInfo.host, defaultPort, region, dbUser, mockCredentials, instance(mockPluginService))
spyIamUtils.generateAuthenticationToken(hostInfo.host, defaultPort, region, dbUser, testCredentials, instance(mockPluginService))
).called();
expect(dbUser).toBe(WrapperProperties.USER.get(props));
expect(testToken).toBe(WrapperProperties.PASSWORD.get(props));
Expand All @@ -107,7 +108,7 @@ describe("oktaAuthTest", () => {
await spyPluginInstance.connect(hostInfo, props, true, mockConnectFunc);

verify(
spyIamUtils.generateAuthenticationToken(hostInfo.host, defaultPort, region, dbUser, mockCredentials, instance(mockPluginService))
spyIamUtils.generateAuthenticationToken(hostInfo.host, defaultPort, region, dbUser, testCredentials, instance(mockPluginService))
).called();
expect(dbUser).toBe(WrapperProperties.USER.get(props));
expect(testToken).toBe(WrapperProperties.PASSWORD.get(props));
Expand Down Expand Up @@ -158,7 +159,7 @@ describe("oktaAuthTest", () => {

await spyPluginInstance.connect(hostInfo, props, true, mockConnectFunc);

verify(spyIamUtils.generateAuthenticationToken(iamHost, defaultPort, region, dbUser, mockCredentials, instance(mockPluginService))).called();
verify(spyIamUtils.generateAuthenticationToken(iamHost, defaultPort, region, dbUser, testCredentials, instance(mockPluginService))).called();
expect(dbUser).toBe(WrapperProperties.USER.get(props));
expect(testToken).toBe(WrapperProperties.PASSWORD.get(props));
});
Expand Down