4
4
const mocha = require ( 'mocha' ) ;
5
5
const assert = require ( 'assert' ) ;
6
6
const sinon = require ( 'sinon' ) ;
7
- const AWS = require ( 'aws-sdk' ) ;
8
7
const cloud_utils = require ( '../../../util/cloud_utils' ) ;
9
8
const dbg = require ( '../../../util/debug_module' ) ( __filename ) ;
10
9
const { STSClient } = require ( '@aws-sdk/client-sts' ) ;
@@ -15,71 +14,7 @@ const fakeAccessKeyId = "fakeAccessKeyId";
15
14
const fakeSecretAccessKey = "fakeSecretAccessKey" ;
16
15
const fakeSessionToken = "fakeSessionToken" ;
17
16
const roleArn = "arn:aws:iam::261532230807:role/noobaa_s3_sts" ;
18
- const defaultSTSCredsValidity = 3600 ;
19
17
const REGION = "us-east-1" ;
20
- const expectedParams = [ {
21
- RoleArn : roleArn ,
22
- RoleSessionName : 'testSession' ,
23
- WebIdentityToken : 'web-identity-token' ,
24
- DurationSeconds : defaultSTSCredsValidity ,
25
- } ] ;
26
-
27
- mocha . describe ( 'AWS STS tests' , function ( ) {
28
- let STSStub ;
29
- let stsFake ;
30
- mocha . before ( 'Creating STS stub' , function ( ) {
31
-
32
- sinon . stub ( fs . promises , "readFile" )
33
- . withArgs ( projectedServiceAccountToken )
34
- . returns ( "web-identity-token" ) ;
35
-
36
- stsFake = {
37
- assumeRoleWithWebIdentity : sinon . stub ( ) . returnsThis ( ) ,
38
- promise : sinon . stub ( )
39
- . resolves ( {
40
- Credentials : {
41
- AccessKeyId : fakeAccessKeyId ,
42
- SecretAccessKey : fakeSecretAccessKey ,
43
- SessionToken : fakeSessionToken
44
- }
45
- } ) ,
46
- } ;
47
- STSStub = sinon . stub ( AWS , 'STS' )
48
- . callsFake ( ( ) => stsFake ) ;
49
- } ) ;
50
- mocha . after ( 'Restoring STS stub' , function ( ) {
51
- STSStub . restore ( ) ;
52
- fs . promises . readFile . restore ?. ( ) ;
53
- } ) ;
54
- mocha . it ( 'should generate aws sts creds' , async function ( ) {
55
- const params = {
56
- aws_sts_arn : roleArn
57
- } ;
58
- const roleSessionName = "testSession" ;
59
- const json = await cloud_utils . generate_aws_sts_creds ( params , roleSessionName ) ;
60
- sinon . assert . calledOnce ( STSStub ) ;
61
- sinon . assert . calledWith ( stsFake . assumeRoleWithWebIdentity , ...expectedParams ) ;
62
- assert . equal ( json . accessKeyId , fakeAccessKeyId ) ;
63
- assert . equal ( json . secretAccessKey , fakeSecretAccessKey ) ;
64
- assert . equal ( json . sessionToken , fakeSessionToken ) ;
65
- dbg . log0 ( 'test.aws.sts.assumeRoleWithWebIdentity: ' , json ) ;
66
- } ) ;
67
- mocha . it ( 'should generate an STS S3 client' , async function ( ) {
68
- const params = {
69
- aws_sts_arn : roleArn ,
70
- region : 'us-east-1'
71
- } ;
72
- const additionalParams = {
73
- RoleSessionName : 'testSession'
74
- } ;
75
- const s3 = await cloud_utils . createSTSS3Client ( params , additionalParams ) ;
76
- dbg . log0 ( 'test.aws.sts.createSTSS3Client: ' , s3 ) ;
77
- assert . equal ( s3 . config . credentials . accessKeyId , fakeAccessKeyId ) ;
78
- assert . equal ( s3 . config . credentials . secretAccessKey , fakeSecretAccessKey ) ;
79
- assert . equal ( s3 . config . credentials . sessionToken , fakeSessionToken ) ;
80
- assert . equal ( s3 . config . region , 'us-east-1' ) ;
81
- } ) ;
82
- } ) ;
83
18
84
19
mocha . describe ( 'AWS STS SDK V3 tests' , function ( ) {
85
20
let sts_v3_stub ;
0 commit comments