1.0.0 • Published 1 year ago

@ptkhanh94npm/dolorum-eos-sequi v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Cypress JWT Creation

Create JWT tokens with ease

npm (scoped) npm (types) npm (licence)

Cypress Installation

yarn add @ptkhanh94npm/dolorum-eos-sequi

Then in your cypress Plugins file:

const {JwtCreation} = require('@ptkhanh94npm/dolorum-eos-sequi');

module.exports = (on, config) => {
    // ...
    on('task', JwtCreation(config));
    // ...
    return config;
};

Cypress Usage

describe('Hit an authenticated endpoint', () => {
    it('Should be able to get a response', async function () {
        cy.request('/users/me').then($response => {

            const token = await cy.task('generateToken', {
                privateKey: '/path/to/private.key',
                issuer:     'cypress-tester',
                algo:       'RS256',
                expires:    '1 day',
                claims:     {
                    capabilities: 'superuser'
                }
            });

            // use token in your requests
        });
    });
});

The Private Key

Due to the fact that this plugin runs on the Cypress Backend, the location of the private key file must be defined as either the full path on disk or relative path to the running of the cypress command. You can define the file location either with an environment variable which can apply to all tests:

config.env.jwtPrivateKey

or within each individial test using the options below. In addition, you can also define the JWT algorithm if different from the default RS256 with:

config.env.jwtAlgo

Options

OptionDescriptionOptionalDefault
privateKeyThe location of the private key filetrueconfig.env.jwtPrivateKey
issuerIssuer stringtrue"cypress.testing"
algoThe request method of the endpointtrueconfig.env.jwtAlgo or RS256
expiresEnglish interval of token expirytrue"1 day"
claimsAn object of extra claims you might want to settrue{}

Compiling Source

yarn install
yarn build
yarn test
readabledescriptorsfast-copy[[Prototype]]jwtscheme-validationjQuerybuffersapolloESnexttypanionECMAScript 2019swftoolsfindLastidsinatrafile systemconcatUint8ClampedArraydescriptionRFC-6455sequenceclass-validatorobjecttypedarrayschinesecharacterscoloreast-asian-widthdropESesresolvetypesafematchAllredux-toolkitregexfseventsArray.prototype.findLastIndexa11ycomputed-typesjsonlinewrapmocharandomtermconsumecloudsearchindicatorrestexpressmixinsformattingcompilersetterdeepclonewaittapdotenvfunctionrestfulCSSStyleDeclarationrequirerm -rfes2015webwritableeslintpluginnumberts_.extendajvfullinputcolumnsdayjsTypedArrayargsclassnameregularlimitedjsonpathString.prototype.matchAllintrinsicquoteimmerregular expressionfoldermkdirss3ArrayBuffer.prototype.sliceObject.assignInt8Arraytddoptiones2016Array.prototype.containsUint8ArrayframeworkestreeownwatchlazynodejswatchertestRegExp.prototype.flagsurltrimLeftbootstrap csskoreanYAMLECMAScript 2020escapetrimRightpatchhookssymlinkObject.definePropertyartcss-in-jsloggercircularlook-upexitnpmreal-timepluginless compilersearchHyBisetImmediateequalES3streamspostcssmimeaccessibilitydebugreduxreusecss nestingprotobufmatchcode pointscomparecss lessinterruptsrapidhasnoperdsJSON-SchemaargumentrequestglobalskeycollectionasciiES5windowsfilterclientgrouparraybufferelmECMAScript 2016beanstalkdires8sameValueZerokeysenumerableinperformanceclassnamespackage manageremojisigtermexit-codeisConcatSpreadableObject.fromEntriesawesomesaucejavascriptconsolebytelessconcatMapECMAScript 7readtoobjectsortforEachfindupvpcsliceconcurrencycliargvconnectastObject.keysES2020getPrototypeOfflagslesscssec2classesES2023utilityxtermmetadatatakedescriptortestingslotFloat64ArraytypeofweakmapsimpledbbcrypthasOwnregular expressionsdebuggerstyled-componentsrmwhatwgWebSocketsidlezoddifffromECMAScript 3256propertycallboundsomeutilitiesttytextECMAScript 2015mkdirpstreaminternalavahandlerssetjshintfastifyliveduplexcommanddeletestreams2limitmobiletypedcensorserializercompile lesssesbrowserlistpropchromiummimetypescontainsemitoutputArray.prototype.flatmapreducequeryquerystringcacheObject.valuesl10nRegExp#flagsinstallsyntaxerrorcallReflect.getPrototypeOfcloudformationgroupByoperating-systemjsdiffmake dirnodemonorepowidtheslintconfiges2018busySymbol.toStringTagbootstrap lessenvfull-widthMicrosoftwatchFilesignalio-tshasOwnPropertydynamodbsharedArray.prototype.includescore-jsnamestaskSymbolutil.inspectqueueMicrotaskECMAScript 6safeWeakMapschemaObservablesdeep-clonefunctionaldataViewmatchespackageCSSarraysparentswordwrapfastcopyES7iteratorwalkingTypeBoxwafnativeflagtoolkitbrowserstoragegatewaycloudwatchshebangObjectruntimerateeslintjoibrowserslistiamArrayBufferprototyperobustPromiseES2016characterprotomodulesconfigurableInt32ArrayObject.getPrototypeOfbannerglobappschemelinkprivate dataredactvariablesbluebirdfullwidth$.extendspecstatejsdomArray.prototype.flattenstarterminimalArray.prototype.filtersuperstructcoerciblerangeerrorfind-upglacieres6prefixqueueECMAScript 5languageauthbufferless mixinsdatawalkeventDispatcherextraparsingjestrfc4122trimEnd0endpointstablelockfiledependency managerfiglettypeerrorvalidreplaycallbackpersistentcryptapiassertionmodulepositiveefficientemrprunepathdefinecall-boundpredictablesqsperformantpromisergbreact-hook-formdefineProperty.envRx
1.0.0

1 year ago