@@ -15,6 +15,7 @@ const { ListUsersCommand, CreateUserCommand, GetUserCommand, UpdateUserCommand,
1515 ListAccessKeysCommand, CreateAccessKeyCommand, GetAccessKeyLastUsedCommand,
1616 UpdateAccessKeyCommand, DeleteAccessKeyCommand,
1717 ListUserPoliciesCommand, PutUserPolicyCommand, DeleteUserPolicyCommand, GetUserPolicyCommand,
18+ ListUserTagsCommand, TagUserCommand, UntagUserCommand,
1819 ListGroupsForUserCommand, ListAccountAliasesCommand, ListAttachedGroupPoliciesCommand,
1920 ListAttachedRolePoliciesCommand, ListAttachedUserPoliciesCommand, ListEntitiesForPolicyCommand,
2021 ListGroupPoliciesCommand, ListGroupsCommand, ListInstanceProfilesCommand,
@@ -24,7 +25,7 @@ const { ListUsersCommand, CreateUserCommand, GetUserCommand, UpdateUserCommand,
2425 ListRoleTagsCommand, ListSAMLProvidersCommand, ListServerCertificatesCommand,
2526 ListServerCertificateTagsCommand, ListServiceSpecificCredentialsCommand,
2627 ListSigningCertificatesCommand, ListSSHPublicKeysCommand,
27- ListUserTagsCommand , ListVirtualMFADevicesCommand } = require ( '@aws-sdk/client-iam' ) ;
28+ ListVirtualMFADevicesCommand } = require ( '@aws-sdk/client-iam' ) ;
2829const { ACCESS_KEY_STATUS_ENUM } = require ( '../../../../endpoint/iam/iam_constants' ) ;
2930const IamError = require ( '../../../../endpoint/iam/iam_errors' ) . IamError ;
3031
@@ -258,7 +259,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
258259 } ) ;
259260 } ) ;
260261
261- mocha . describe ( 'IAM User Policy API' , async function ( ) {
262+ mocha . describe ( 'IAM User Policy API' , async function ( ) {
262263 if ( is_nc_coretest ) this . skip ( ) ; // eslint-disable-line no-invalid-this
263264 const username3 = 'Kai' ;
264265 const policy_name = 'AllAccessPolicy' ;
@@ -359,8 +360,94 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
359360 } ) ;
360361 } ) ;
361362
363+ mocha . describe ( 'IAM User Tags API' , async function ( ) {
364+ if ( is_nc_coretest ) this . skip ( ) ; // eslint-disable-line no-invalid-this
365+ const username4 = 'Itsuki' ;
366+ const user_tag_1 = {
367+ Key : "CostCenter" ,
368+ Value : "12345"
369+ } ;
370+ const user_tag_2 = {
371+ Key : "Department" ,
372+ Value : "Accounting"
373+ } ;
374+
375+ const user_tags = [ user_tag_1 , user_tag_2 ] ;
376+
377+ mocha . before ( async ( ) => {
378+ // create a user
379+ const input = {
380+ UserName : username4
381+ } ;
382+ const command = new CreateUserCommand ( input ) ;
383+ const response = await iam_account . send ( command ) ;
384+ _check_status_code_ok ( response ) ;
385+ } ) ;
386+
387+ mocha . after ( async ( ) => {
388+ // delete a user
389+ const input = {
390+ UserName : username4
391+ } ;
392+ const command = new DeleteUserCommand ( input ) ;
393+ const response = await iam_account . send ( command ) ;
394+ _check_status_code_ok ( response ) ;
395+ } ) ;
396+
397+ mocha . it ( 'list user tags - should be empty' , async function ( ) {
398+ const input = {
399+ UserName : username4 ,
400+ } ;
401+ const command = new ListUserTagsCommand ( input ) ;
402+ const response = await iam_account . send ( command ) ;
403+ _check_status_code_ok ( response ) ;
404+ assert . equal ( response . Tags . length , 0 ) ;
405+ } ) ;
406+
407+ mocha . it ( 'tag user' , async function ( ) {
408+ const input = {
409+ UserName : username4 ,
410+ Tags : user_tags
411+ } ;
412+ const command = new TagUserCommand ( input ) ;
413+ const response = await iam_account . send ( command ) ;
414+ _check_status_code_ok ( response ) ;
415+
416+ // verify it using list user tags
417+ const input2 = {
418+ UserName : username4
419+ } ;
420+ const command2 = new ListUserTagsCommand ( input2 ) ;
421+ const response2 = await iam_account . send ( command2 ) ;
422+ _check_status_code_ok ( response2 ) ;
423+ assert . equal ( response2 . Tags . length , 2 ) ;
424+ const sorted = arr => _ . sortBy ( arr , 'Key' ) ;
425+ assert . deepEqual ( sorted ( response2 . Tags ) , sorted ( user_tags ) ) ;
426+ } ) ;
427+
428+ mocha . it ( 'untag user' , async function ( ) {
429+ const input = {
430+ UserName : username4 ,
431+ TagKeys : [ user_tag_2 . Key ]
432+ } ;
433+ const command = new UntagUserCommand ( input ) ;
434+ const response = await iam_account . send ( command ) ;
435+ _check_status_code_ok ( response ) ;
436+
437+ // verify it using list user tags
438+ const input2 = {
439+ UserName : username4
440+ } ;
441+ const command2 = new ListUserTagsCommand ( input2 ) ;
442+ const response2 = await iam_account . send ( command2 ) ;
443+ _check_status_code_ok ( response2 ) ;
444+ assert . equal ( response2 . Tags . length , 1 ) ;
445+ assert . deepEqual ( response2 . Tags , [ user_tag_1 ] ) ;
446+ } ) ;
447+ } ) ;
448+
362449 mocha . describe ( 'IAM other APIs (currently returns empty value)' , async function ( ) {
363- const username3 = 'Emi' ;
450+ const username5 = 'Emi' ;
364451 const group_name = 'my_group' ;
365452 const role_name = 'my_role' ;
366453 const instance_profile_name = 'my_instance_profile_name' ;
@@ -369,7 +456,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
369456 mocha . before ( async ( ) => {
370457 // create a user
371458 const input = {
372- UserName : username3
459+ UserName : username5
373460 } ;
374461 const command = new CreateUserCommand ( input ) ;
375462 const response = await iam_account . send ( command ) ;
@@ -379,7 +466,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
379466 mocha . after ( async ( ) => {
380467 // delete a user
381468 const input = {
382- UserName : username3
469+ UserName : username5
383470 } ;
384471 const command = new DeleteUserCommand ( input ) ;
385472 const response = await iam_account . send ( command ) ;
@@ -402,7 +489,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
402489
403490 mocha . it ( 'list groups for user - should be empty' , async function ( ) {
404491 const input = {
405- UserName : username3
492+ UserName : username5
406493 } ;
407494 const command = new ListGroupsForUserCommand ( input ) ;
408495 const response = await iam_account . send ( command ) ;
@@ -454,7 +541,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
454541
455542 mocha . it ( 'list attached user policies for user - should be empty' , async function ( ) {
456543 const input = {
457- UserName : username3
544+ UserName : username5
458545 } ;
459546 const command = new ListAttachedUserPoliciesCommand ( input ) ;
460547 const response = await iam_account . send ( command ) ;
@@ -546,7 +633,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
546633
547634 mocha . it ( 'list MFA devices for user - should be empty' , async function ( ) {
548635 const input = {
549- UserName : username3
636+ UserName : username5
550637 } ;
551638 const command = new ListMFADevicesCommand ( input ) ;
552639 const response = await iam_account . send ( command ) ;
@@ -702,7 +789,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
702789
703790 mocha . it ( 'list service specific credentials for user - should be empty' , async function ( ) {
704791 const input = {
705- UserName : username3
792+ UserName : username5
706793 } ;
707794 const command = new ListServiceSpecificCredentialsCommand ( input ) ;
708795 const response = await iam_account . send ( command ) ;
@@ -734,7 +821,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
734821
735822 mocha . it ( 'list signing certificates for user - should be empty' , async function ( ) {
736823 const input = {
737- UserName : username3
824+ UserName : username5
738825 } ;
739826 const command = new ListSigningCertificatesCommand ( input ) ;
740827 const response = await iam_account . send ( command ) ;
@@ -766,7 +853,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
766853
767854 mocha . it ( 'list SSH public keys for user - should be empty' , async function ( ) {
768855 const input = {
769- UserName : username3
856+ UserName : username5
770857 } ;
771858 const command = new ListSSHPublicKeysCommand ( input ) ;
772859 const response = await iam_account . send ( command ) ;
@@ -798,7 +885,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
798885
799886 mocha . it ( 'list user policies for user - should be empty' , async function ( ) {
800887 const input = {
801- UserName : username3
888+ UserName : username5
802889 } ;
803890 const command = new ListUserPoliciesCommand ( input ) ;
804891 const response = await iam_account . send ( command ) ;
@@ -822,7 +909,7 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
822909
823910 mocha . it ( 'list user tags for user - should be empty' , async function ( ) {
824911 const input = {
825- UserName : username3
912+ UserName : username5
826913 } ;
827914 const command = new ListUserTagsCommand ( input ) ;
828915 const response = await iam_account . send ( command ) ;
0 commit comments