@@ -927,6 +927,141 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
927927 } ) ;
928928} ) ;
929929
930+ mocha . describe ( 'IAM advanced integration tests' , async function ( ) {
931+ mocha . describe ( 'IAM User API' , async function ( ) {
932+ const username = 'Mateo' ;
933+ const username_lowercase = username . toLowerCase ( ) ;
934+ const username_uppercase = username . toUpperCase ( ) ;
935+
936+ mocha . describe ( 'IAM CreateUser API' , async function ( ) {
937+ mocha . before ( async ( ) => {
938+ // create a user
939+ const input = {
940+ UserName : username
941+ } ;
942+ const command = new CreateUserCommand ( input ) ;
943+ const response = await iam_account . send ( command ) ;
944+ _check_status_code_ok ( response ) ;
945+ } ) ;
946+
947+ mocha . after ( async ( ) => {
948+ // delete a user
949+ const input = {
950+ UserName : username
951+ } ;
952+ const command = new DeleteUserCommand ( input ) ;
953+ const response = await iam_account . send ( command ) ;
954+ _check_status_code_ok ( response ) ;
955+ } ) ;
956+
957+ mocha . it ( 'create a user with username that already exists should fail' , async function ( ) {
958+ try {
959+ const input = {
960+ UserName : username
961+ } ;
962+ const command = new CreateUserCommand ( input ) ;
963+ await iam_account . send ( command ) ;
964+ assert . fail ( 'create user with existing username - should throw an error' ) ;
965+ } catch ( err ) {
966+ const err_code = err . Error . Code ;
967+ assert . equal ( err_code , IamError . EntityAlreadyExists . code ) ;
968+ }
969+ } ) ;
970+
971+ mocha . it ( 'create a user with username that already exists (lower case) should fail' , async function ( ) {
972+ try {
973+ const input = {
974+ UserName : username_lowercase
975+ } ;
976+ const command = new CreateUserCommand ( input ) ;
977+ await iam_account . send ( command ) ;
978+ assert . fail ( 'create user with existing username (lower case) - should throw an error' ) ;
979+ } catch ( err ) {
980+ const err_code = err . Error . Code ;
981+ assert . equal ( err_code , IamError . EntityAlreadyExists . code ) ;
982+ }
983+ } ) ;
984+
985+ mocha . it ( 'create a user with username that already exists (upper case) should fail' , async function ( ) {
986+ try {
987+ const input = {
988+ UserName : username_uppercase
989+ } ;
990+ const command = new CreateUserCommand ( input ) ;
991+ await iam_account . send ( command ) ;
992+ assert . fail ( 'create user with existing username (upper case) - should throw an error' ) ;
993+ } catch ( err ) {
994+ const err_code = err . Error . Code ;
995+ assert . equal ( err_code , IamError . EntityAlreadyExists . code ) ;
996+ }
997+ } ) ;
998+ } ) ;
999+
1000+ mocha . describe ( 'IAM UpdateUser API' , async function ( ) {
1001+ mocha . before ( async ( ) => {
1002+ // create a user
1003+ const input = {
1004+ UserName : username
1005+ } ;
1006+ const command = new CreateUserCommand ( input ) ;
1007+ const response = await iam_account . send ( command ) ;
1008+ _check_status_code_ok ( response ) ;
1009+ } ) ;
1010+
1011+ mocha . after ( async ( ) => {
1012+ // delete a user
1013+ const input = {
1014+ UserName : username
1015+ } ;
1016+ const command = new DeleteUserCommand ( input ) ;
1017+ const response = await iam_account . send ( command ) ;
1018+ _check_status_code_ok ( response ) ;
1019+ } ) ;
1020+
1021+ mocha . it ( 'update a user with same username' , async function ( ) {
1022+ const input = {
1023+ UserName : username ,
1024+ NewUserName : username ,
1025+ } ;
1026+ const command = new UpdateUserCommand ( input ) ;
1027+ const response = await iam_account . send ( command ) ;
1028+ _check_status_code_ok ( response ) ;
1029+ } ) ;
1030+
1031+ mocha . it ( 'update a user with new username that already exists (lower case) should fail' , async function ( ) {
1032+ try {
1033+ const input = {
1034+ UserName : username ,
1035+ NewUserName : username_lowercase ,
1036+ } ;
1037+ const command = new UpdateUserCommand ( input ) ;
1038+ await iam_account . send ( command ) ;
1039+ assert . fail ( 'update user with existing username (lower case) - should throw an error' ) ;
1040+ } catch ( err ) {
1041+ const err_code = err . Error . Code ;
1042+ assert . equal ( err_code , IamError . EntityAlreadyExists . code ) ;
1043+ }
1044+ } ) ;
1045+
1046+ mocha . it ( 'update a user with new username that already exists (upper case) should fail' , async function ( ) {
1047+ try {
1048+ const input = {
1049+ UserName : username ,
1050+ NewUserName : username_uppercase ,
1051+ } ;
1052+ const command = new UpdateUserCommand ( input ) ;
1053+ await iam_account . send ( command ) ;
1054+ assert . fail ( 'update user with existing username (upper case) - should throw an error' ) ;
1055+ } catch ( err ) {
1056+ const err_code = err . Error . Code ;
1057+ assert . equal ( err_code , IamError . EntityAlreadyExists . code ) ;
1058+ }
1059+ } ) ;
1060+ } ) ;
1061+
1062+ } ) ;
1063+ } ) ;
1064+
9301065/**
9311066 * _check_status_code_ok is an helper function to check that we got an response from the server
9321067 * @param {{ $metadata: { httpStatusCode: number; }; } } response
0 commit comments