Skip to content

Commit d4d5ec4

Browse files
Merge pull request #100 from muzzammilshahid/interop-tests
Add interop tests for cryptosign operations
2 parents 86065b7 + 41229e4 commit d4d5ec4

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

.github/workflows/main.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ jobs:
2828
- name: Check lint
2929
run: make lint
3030

31+
- name: build wampproto-cli
32+
run: make build-wampproto
33+
3134
- name: Run tests
3235
run: make tests

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ format:
1515

1616
tests:
1717
dart test
18+
19+
build-wampproto:
20+
git clone https://github.com/xconnio/wampproto-cli.git
21+
cd wampproto-cli/ && make build && sudo cp ./wampproto /usr/local/bin/

test/interoptests/auth_test.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import "dart:io";
2+
3+
import "package:pinenacl/ed25519.dart";
4+
import "package:test/test.dart";
5+
6+
import "package:wampproto/src/auth/cryptosign.dart";
7+
8+
Future<String> runCommand(String command) async {
9+
ProcessResult result = await Process.run("wampproto", command.split(" "));
10+
expect(result.exitCode, 0, reason: result.stderr);
11+
12+
return result.stdout;
13+
}
14+
15+
void main() {
16+
group("CryptoSignAuth", () {
17+
const testPublicKey = "2b7ec216daa877c7f4c9439db8a722ea2340eacad506988db2564e258284f895";
18+
const testPrivateKey = "022b089bed5ab78808365e82dd12c796c835aeb98b4a5a9e099d3e72cb719516";
19+
20+
test("GenerateChallenge", () async {
21+
var challenge = generateCryptoSignChallenge();
22+
23+
var signature = await runCommand(
24+
"auth cryptosign sign-challenge --challenge $challenge --private-key $testPrivateKey",
25+
);
26+
27+
var isVerified = await runCommand(
28+
"auth cryptosign verify-signature --signature ${signature.trim()} --public-key $testPublicKey",
29+
);
30+
expect(isVerified, "Signature verified successfully\n");
31+
});
32+
33+
test("SignCryptoSignChallenge", () async {
34+
var challenge = await runCommand("auth cryptosign generate-challenge");
35+
36+
var signature = signCryptoSignChallenge(
37+
challenge.trim(),
38+
SigningKey(seed: Base16Encoder.instance.decode(testPrivateKey)),
39+
);
40+
41+
if (Base16Encoder.instance.decode(signature).length == 64) {
42+
signature = signature + challenge.trim();
43+
}
44+
45+
var isVerified = await runCommand(
46+
"auth cryptosign verify-signature --signature $signature --public-key $testPublicKey",
47+
);
48+
expect(isVerified, "Signature verified successfully\n");
49+
});
50+
51+
test("VerifyCryptoSignSignature", () async {
52+
var challenge = await runCommand("auth cryptosign generate-challenge");
53+
54+
var signature = await runCommand(
55+
"auth cryptosign sign-challenge --challenge ${challenge.trim()} --private-key $testPrivateKey",
56+
);
57+
58+
var isVerified = verifyCryptoSignSignature(signature.trim(), Base16Encoder.instance.decode(testPublicKey));
59+
expect(isVerified, true);
60+
});
61+
});
62+
}

0 commit comments

Comments
 (0)