@@ -763,4 +763,52 @@ describe('key protect v2 integration', () => {
763763 done ( ) ;
764764 } ) ;
765765 } ) ;
766+ describe ( 'key alias extensions' , ( ) => {
767+ it ( 'checkKeyaliasExtension' , async done => {
768+ let response ;
769+ const samplePlaintext = 'dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmcK' ;
770+ try {
771+ // create a key alias
772+ const keyAlias = 'nodejsAlias' ;
773+ const createKeyAliasParams = Object . assign ( { } , options ) ;
774+ createKeyAliasParams . id = keyId ;
775+ createKeyAliasParams . alias = keyAlias ;
776+ response = await keyProtectClient . createKeyAlias ( createKeyAliasParams ) ;
777+ expect ( response ) . toBeDefined ( ) ;
778+ expect ( response . status ) . toEqual ( 201 ) ;
779+
780+ // wrap using key alias
781+ const wrapKeyParams = Object . assign ( { } , options ) ;
782+ wrapKeyParams . id = createKeyAliasParams . alias ;
783+ wrapKeyParams . keyActionWrapBody = {
784+ plaintext : samplePlaintext ,
785+ } ;
786+ response = await keyProtectClient . wrapKey ( wrapKeyParams ) ;
787+ const ciphertextResult = response . result . ciphertext ;
788+ expect ( response ) . toBeDefined ( ) ;
789+ expect ( response . status ) . toEqual ( 200 ) ;
790+
791+ // un-wrap using key alias
792+ const unwrapKeyParams = Object . assign ( { } , options ) ;
793+ unwrapKeyParams . id = createKeyAliasParams . alias ;
794+ unwrapKeyParams . keyActionUnwrapBody = {
795+ ciphertext : ciphertextResult ,
796+ } ;
797+ response = await keyProtectClient . unwrapKey ( unwrapKeyParams ) ;
798+ const plaintextResult = response . result . plaintext ;
799+ expect ( response ) . toBeDefined ( ) ;
800+ expect ( plaintextResult ) . toEqual ( samplePlaintext ) ;
801+ expect ( response . status ) . toEqual ( 200 ) ;
802+
803+ // delete a key using key alias
804+ const deleteKeyParams = Object . assign ( { } , options ) ;
805+ deleteKeyParams . id = createKeyAliasParams . alias ;
806+ deleteKeyParams . prefer = 'return=representation' ;
807+ await keyProtectClient . deleteKey ( deleteKeyParams ) ;
808+ } catch ( err ) {
809+ done ( err ) ;
810+ }
811+ done ( ) ;
812+ } ) ;
813+ } ) ;
766814} ) ;
0 commit comments