Skip to content

Commit c1af757

Browse files
committed
cdt-27 - tests implemented
Signed-off-by: ashish <[email protected]>
1 parent 1221bd6 commit c1af757

File tree

4 files changed

+145
-21
lines changed

4 files changed

+145
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Please feel free to provide any suggestion for new utility in [Issues](https://g
221221

222222
## @codingtools/cdt
223223

224-
This Project is created and supported by [Ashish Patel](http://ashish.live/)
224+
This Project is created and managed by [Ashish Patel](http://ashish.live/)
225225

226226
## Releasing Version
227227
* this needs to be done from release* branch

package-lock.json

Lines changed: 92 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/crypto.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class Crypto extends Command {
2828
args.type = flags.encryption ? flags.encryption : flags.decryption //type like AES,DES
2929

3030
this.checkParameters(flags, args)
31-
flags.encryption ? this.Encrypt(flags, args) : this.Decrypt(flags, args)
31+
return flags.encryption ? this.Encrypt(flags, args) : this.Decrypt(flags, args)
3232
}
3333

3434
private Encrypt(flags: any, args: any) {
@@ -39,6 +39,7 @@ export default class Crypto extends Command {
3939
mode: this.getCryptoMode(flags)
4040
}).toString()
4141
Logger.success(this, `${encrypted}`)
42+
return encrypted
4243
}
4344

4445
private Decrypt(flags: any, args: any) {
@@ -49,6 +50,7 @@ export default class Crypto extends Command {
4950
mode: this.getCryptoMode(flags)
5051
}).toString(CryptoJS.enc.Utf8)
5152
Logger.success(this, `${decrypted}`)
53+
return decrypted
5254
}
5355

5456
private getCryptoType(type: string) {

test/commands/crypto.test.ts

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
import {expect, test} from '@oclif/test'
2-
// @ts-ignore
3-
import jest from 'jest-mock'
4-
52
import Crypto from '../../src/commands/crypto'
63

74
describe('crypto', () => {
8-
// // TODO: its not possible to predict the encription for a message so we can't write this,however decription is predictible
9-
// test
10-
// .stdout()
11-
// .command(['crypto', '-e', 'aes', '-s', 'Message', '-k', 'Secret Passphrase'])
12-
// .it('runs hello', ctx => {
13-
// expect(ctx.stdout).to.contain('73e54154a15d1beeb509d9e12f1e462a0')
14-
// })
15-
//
165

176
test
187
.stdout()
@@ -110,4 +99,53 @@ describe('crypto', () => {
11099
expect(ctx.stdout).to.contain('Neither encryption or decryption methods passed')
111100
})
112101

102+
103+
test
104+
.stdout()
105+
.it('AES encryption and decryption Integration Test', async(ctx) => {
106+
let encrypt = await Crypto.run(['crypto', '-e', 'aes', '-s', 'Message', '-k', 'secret']);
107+
let decrypt = await Crypto.run(['crypto', '-d', 'aes', '-s', encrypt, '-k', 'secret']);
108+
expect(decrypt).to.contain('Message');
109+
});
110+
111+
test
112+
.stdout()
113+
.it('DES encryption and decryption Integration Test', async(ctx) => {
114+
let encrypt = await Crypto.run(['crypto', '-e', 'DES', '-s', 'Message', '-k', 'secret']);
115+
let decrypt = await Crypto.run(['crypto', '-d', 'DES', '-s', encrypt, '-k', 'secret']);
116+
expect(decrypt).to.contain('Message');
117+
});
118+
119+
test
120+
.stdout()
121+
.it('3DES encryption and decryption Integration Test', async(ctx) => {
122+
let encrypt = await Crypto.run(['crypto', '-e', '3DES', '-s', 'Message', '-k', 'secret']);
123+
let decrypt = await Crypto.run(['crypto', '-d', '3DES', '-s', encrypt, '-k', 'secret']);
124+
expect(decrypt).to.contain('Message');
125+
});
126+
127+
test
128+
.stdout()
129+
.it('Rabbit encryption and decryption Integration Test', async(ctx) => {
130+
let encrypt = await Crypto.run(['crypto', '-e', 'Rabbit', '-s', 'Message', '-k', 'secret']);
131+
let decrypt = await Crypto.run(['crypto', '-d', 'Rabbit', '-s', encrypt, '-k', 'secret']);
132+
expect(decrypt).to.contain('Message');
133+
});
134+
135+
test
136+
.stdout()
137+
.it('RC4 encryption and decryption Integration Test', async(ctx) => {
138+
let encrypt = await Crypto.run(['crypto', '-e', 'RC4', '-s', 'Message', '-k', 'secret']);
139+
let decrypt = await Crypto.run(['crypto', '-d', 'RC4', '-s', encrypt, '-k', 'secret']);
140+
expect(decrypt).to.contain('Message');
141+
});
142+
143+
test
144+
.stdout()
145+
.it('RC4Drop encryption and decryption Integration Test', async(ctx) => {
146+
let encrypt = await Crypto.run(['crypto', '-e', 'RC4Drop', '-s', 'Message', '-k', 'secret']);
147+
let decrypt = await Crypto.run(['crypto', '-d', 'RC4Drop', '-s', encrypt, '-k', 'secret']);
148+
expect(decrypt).to.contain('Message');
149+
});
150+
113151
})

0 commit comments

Comments
 (0)