@@ -10,9 +10,8 @@ import { SsmClient } from '../../../shared/clients/ssm'
1010import { Ec2Client } from '../../../shared/clients/ec2'
1111import { Ec2Selection } from '../../../awsService/ec2/prompter'
1212import { ToolkitError } from '../../../shared/errors'
13- import { IAM } from 'aws-sdk'
1413import { SshKeyPair } from '../../../awsService/ec2/sshKeyPair'
15- import { IamClient } from '../../../shared/clients/iam'
14+ import { IamClient , IamRole } from '../../../shared/clients/iam'
1615import { assertNoTelemetryMatch , createTestWorkspaceFolder } from '../../testUtil'
1716import { fs } from '../../../shared'
1817import path from 'path'
@@ -31,13 +30,11 @@ describe('Ec2ConnectClient', function () {
3130
3231 describe ( 'getAttachedIamRole' , async function ( ) {
3332 it ( 'only returns role if receives ARN from instance profile' , async function ( ) {
34- let role : IAM . Role | undefined
33+ let role : IamRole | undefined
3534 const getInstanceProfileStub = sinon . stub ( Ec2Client . prototype , 'getAttachedIamInstanceProfile' )
3635
3736 getInstanceProfileStub . resolves ( { Arn : 'thisIsAnArn' } )
38- sinon
39- . stub ( IamClient . prototype , 'getIAMRoleFromInstanceProfile' )
40- . resolves ( { Arn : 'ThisIsARoleArn' } as IAM . Role )
37+ sinon . stub ( IamClient . prototype , 'getIAMRoleFromInstanceProfile' ) . resolves ( getFakeRole ( 'ThisIsARoleArn' ) )
4138
4239 role = await client . getAttachedIamRole ( 'test-instance' )
4340 assert . ok ( role )
@@ -116,7 +113,7 @@ describe('Ec2ConnectClient', function () {
116113
117114 it ( 'throws EC2SSMAgent error if instance is running and has IAM Role, but agent is not running' , async function ( ) {
118115 sinon . stub ( Ec2Connecter . prototype , 'isInstanceRunning' ) . resolves ( true )
119- sinon . stub ( Ec2Connecter . prototype , 'getAttachedIamRole' ) . resolves ( { Arn : 'testRole' } as IAM . Role )
116+ sinon . stub ( Ec2Connecter . prototype , 'getAttachedIamRole' ) . resolves ( getFakeRole ( 'testRole' ) )
120117 sinon . stub ( Ec2Connecter . prototype , 'hasProperPermissions' ) . resolves ( true )
121118 sinon . stub ( SsmClient . prototype , 'getInstanceAgentPingStatus' ) . resolves ( 'offline' )
122119
@@ -141,7 +138,7 @@ describe('Ec2ConnectClient', function () {
141138
142139 it ( 'does not throw an error if all checks pass' , async function ( ) {
143140 sinon . stub ( Ec2Connecter . prototype , 'isInstanceRunning' ) . resolves ( true )
144- sinon . stub ( Ec2Connecter . prototype , 'getAttachedIamRole' ) . resolves ( { Arn : 'testRole' } as IAM . Role )
141+ sinon . stub ( Ec2Connecter . prototype , 'getAttachedIamRole' ) . resolves ( getFakeRole ( 'testRole' ) )
145142 sinon . stub ( Ec2Connecter . prototype , 'hasProperPermissions' ) . resolves ( true )
146143 sinon . stub ( SsmClient . prototype , 'getInstanceAgentPingStatus' ) . resolves ( 'Online' )
147144
@@ -307,3 +304,13 @@ describe('getRemoveLinesCommand', async function () {
307304 assert . throws ( ( ) => getRemoveLinesCommand ( 'pat/tern' , 'macOS' , 'test.txt' ) )
308305 } )
309306} )
307+
308+ function getFakeRole ( Arn : string ) {
309+ return {
310+ RoleName : 'hasArn' ,
311+ Arn,
312+ Path : 'thisIsAPath' ,
313+ RoleId : '1' ,
314+ CreateDate : new Date ( ) ,
315+ }
316+ }
0 commit comments