it('Should register user', async () => { const res = await request(app).post('/api/v1/auth/register').send(user).expect(201); delete user.password; user.role = 'user'; expect(res.body.data).to.haveOwnProperty('token'); expect(res.body.data).to.haveOwnProperty('user'); expect(res.body.data.user).to.include(user); });
function expectOrder(order) { expect(order).to.be.an('Object'); expect(order).to.haveOwnProperty('orderId'); expect(order.orderId).to.be.a('Number'); expect(order).to.haveOwnProperty('state'); expect(order.state).to.be.a('String'); expect(order).to.haveOwnProperty('orderTotal'); expect(order.orderTotal).to.be.an('Object'); expect(order.orderTotal).to.haveOwnProperty('amount'); expect(order.orderTotal.amount).to.be.a('Number'); }
it("new key for signing", async () => { let counter = 0; let result = ""; try { result = await tool(["--type", "oct", "--size", "256", "--use", "sign"]); } catch (err) { // this should complain about a missing type. counter = 1; } expect(counter).to.be.equal(0); expect(result.length).not.equal(0); const jsonKey = JSON.parse(result); expect(jsonKey).to.be.an("object"); expect(jsonKey).to.haveOwnProperty("use"); expect(jsonKey.use).to.be.equal("sig"); });
async function getOrder(id) { const res = await chai.request(getServiceUrl('order_service')).get(`/orders/${id}`); expect(res).to.have.status(200); const body = res.body; expect(body).to.be.an('Object'); expect(body).to.haveOwnProperty('orderId'); expect(body.orderId).to.be.a('Number'); expect(body).to.haveOwnProperty('orderState'); expect(body.orderState).to.be.a('String'); return body; }
it("Should upsert a single record", async () => { const record = await resource.upsertOne({ firstname: "Fred" }, { firstname: "Fred", lastname: "Page" }); expect(record).to.haveOwnProperty('_id'); const updatedRecord = await resource.upsertOne({ firstname: "Fred" }, { firstname: "Jimmy" }); expect(updatedRecord._id).to.equal(record._id); expect(updatedRecord.firstname).to.equal("Jimmy"); });
it('Should return access and refresh token if valid credentials provided', async () => { const res = await request(app).post('/api/v1/auth/login').send(dbUser).expect(200); expect(res.body.data.user).to.haveOwnProperty('id'); delete res.body.data.user.id; delete dbUser.password; expect(res.body.data.user).to.include(dbUser); expect(res.body.data.tokens).to.haveOwnProperty('accessToken'); expect(res.body.data.tokens).to.haveOwnProperty('refreshToken'); expect(res.body.data.tokens).to.haveOwnProperty('tokenType'); });
it('converts CL command XML output to js object', function () { const xmlOut = '<?xml version=\'1.0\'?><myscript><cmd exec=\'rexx\' error=\'fast\'>' + '<success>+++ success RTVJOBA USRLIBL(?) SYSLIBL(?)</success>' + '<row><data desc=\'USRLIBL\'>QGPL QTEMP QDEVELOP QBLDSYS' + ' QBLDSYSR</data></row><row><data desc=\'SYSLIBL\'>QSYS' + ' QSYS2 QHLPSYS QUSRSYS</data></row></cmd></myscript>'; const result = xmlToJson(xmlOut); expect(result).to.be.an('array'); expect(result.length).to.equal(1); expect(result[0]).to.be.an('object'); expect(result[0]).to.haveOwnProperty('type').and.to.equal('cmd'); const cmd = 'RTVJOBA USRLIBL(?) SYSLIBL(?)'; expect(result[0]).to.haveOwnProperty('cmd').and.to.equal(cmd); expect(result[0]).to.haveOwnProperty('data'); expect(result[0].data).to.be.an('array'); expect(result[0].data.length).to.equal(2); expect(result[0].data[0]).to.be.an('object'); const name = 'USRLIBL'; expect(result[0].data[0]).to.haveOwnProperty('name').and.to.equal(name); const value = 'QGPL QTEMP QDEVELOP QBLDSYS QBLDSYSR'; expect(result[0].data[0]).to.haveOwnProperty('value').and.to.equal(value); });
it("new rsa 2048 key as keystore", async () => { let counter = 0; let result = ""; try { result = await tool(["--type", "rsa", "-K"]); } catch (err) { // this should complain about a missing type. counter = 1; } expect(counter).to.be.equal(0); expect(result.length).not.equal(0); const jsonKey = JSON.parse(result); expect(jsonKey).to.be.an("object"); expect(jsonKey).to.haveOwnProperty("keys"); expect(jsonKey.keys).to.be.an("array"); expect(jsonKey.keys.length).to.be.equal(1); expect(jsonKey.keys[0]).to.be.an("object"); expect(jsonKey.keys[0].kty).to.be.equal("RSA"); });
it('converts sh command XML output to js object', function () { const xmlOut = '<?xml version=\'1.0\'?><myscript><sh error=\'fast\'>\n' + 'bin\n' + 'ccs\n' + 'icu4c\n' + 'includ\n' + 'lbin\n' + 'lib\n' + 'lib64\n' + 'lpp\n' + 'sbin\n' + 'share\n' + 'vacpp\n' + '</sh>\n' + '</myscript>'; const result = xmlToJson(xmlOut); expect(result).to.be.an('array'); expect(result.length).to.equal(1); expect(result[0]).to.be.an('object'); expect(result[0]).to.haveOwnProperty('type').and.to.equal('sh'); const data = '\nbin\nccs\nicu4c\ninclud\nlbin\nlib\nlib64\nlpp\nsbin\n' + 'share\nvacpp\n'; expect(result[0]).to.haveOwnProperty('data').and.to.equal(data); });
it("new ec 256 key ", async () => { let counter = 0; let result = ""; try { result = await tool(["--type", "ec", "--size", "256"]); } catch (err) { // this should complain about a missing type. counter = 1; } expect(counter).to.be.equal(0); expect(result.length).not.equal(0); const jsonKey = JSON.parse(result); expect(jsonKey).to.be.an("object"); expect(jsonKey).to.haveOwnProperty("kty"); expect(jsonKey.kty).to.be.equal("EC"); expect(jsonKey).to.haveOwnProperty("crv", "P-256"); expect(jsonKey).to.haveOwnProperty("x"); expect(jsonKey).to.haveOwnProperty("y"); expect(jsonKey).to.haveOwnProperty("d"); expect(jsonKey).to.haveOwnProperty("kid"); });
it("new rsa 2048 key in existing keystore", async () => { let counter = 0; let result = ""; try { result = await tool(["--type", "rsa", "-K", "-j", "examples/example-priv.jwks"]); } catch (err) { // this should complain about a missing type. counter = 1; } expect(counter).to.be.equal(0); expect(result.length).not.equal(0); const jsonKey = JSON.parse(result); expect(jsonKey).to.be.an("object"); expect(jsonKey).to.haveOwnProperty("keys"); expect(jsonKey.keys).to.be.an("array"); expect(jsonKey.keys.length).to.be.equal(4); });
it("new oct 256 key ", async () => { let counter = 0; let result = ""; try { result = await tool(["--type", "oct", "--size", "256"]); } catch (err) { // this should complain about a missing type. counter = 1; } expect(counter).to.be.equal(0); expect(result.length).not.equal(0); const jsonKey = JSON.parse(result); expect(jsonKey).to.be.an("object"); expect(jsonKey).to.haveOwnProperty("kty"); expect(jsonKey.kty).to.be.equal("oct"); expect(jsonKey).to.haveOwnProperty("k"); expect(jsonKey).to.haveOwnProperty("kid"); });
it("new key for encrypting with crafted kid", async () => { let counter = 0; let result = ""; try { result = await tool([ "--type", "oct", "--size", "256", "--use", "enc", "--kid", "octopus", ]); } catch (err) { // this should complain about a missing type. counter = 1; } expect(counter).to.be.equal(0); expect(result.length).not.equal(0); const jsonKey = JSON.parse(result); expect(jsonKey).to.be.an("object"); expect(jsonKey).to.haveOwnProperty("use"); expect(jsonKey.use).to.be.equal("enc"); expect(jsonKey.kid).to.be.equal("octopus"); });
it("new key for encrypting", async () => { let counter = 0; let result = ""; try { result = await tool(["--type", "oct", "--size", "256", "--use", "enc"]); } catch (err) { // this should complain about a missing type. counter = 1; } expect(counter).to.be.equal(0); expect(result.length).not.equal(0); const jsonKey = JSON.parse(result); expect(jsonKey).to.be.an("object"); expect(jsonKey).to.haveOwnProperty("use"); expect(jsonKey.use).to.be.equal("enc"); });
it('converts qsh command XML output to js object', function () { const xmlOut = '<?xml version=\'1.0\'?><myscript><qsh error=\'fast\'>\n' + 'bin\n' + 'ccs\n' + 'icu4c\n' + 'includ\n' + 'lbin\n' + 'lib\n' + 'lib64\n' + 'lpp\n' + 'sbin\n' + 'share\n' + 'vacpp\n' + '</qsh>\n' + '</myscript>'; const result = xmlToJson(xmlOut); expect(result).to.be.an('array'); expect(result.length).to.equal(1); expect(result[0]).to.be.an('object'); expect(result[0]).to.haveOwnProperty('type').and.to.equal('qsh'); const data = '\nbin\nccs\nicu4c\ninclud\nlbin\nlib\nlib64\nlpp\nsbin\n' + 'share\nvacpp\n'; expect(result[0]).to.haveOwnProperty('data').and.to.equal(data); });