Skip to content

Commit

Permalink
feat: Add tests for oidc4vc
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed May 3, 2024
1 parent 0a36aed commit 79c248e
Show file tree
Hide file tree
Showing 20 changed files with 1,044 additions and 963 deletions.
1 change: 0 additions & 1 deletion packages/oidc4vc/lib/src/oidc4vc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,6 @@ class OIDC4VC {
}

late final bool isVerified;

if (kty == 'OKP') {
isVerified = verifyTokenEdDSA(
publicKey: publicKeyJwk,
Expand Down
15 changes: 15 additions & 0 deletions packages/oidc4vc/test/src/client_authentication_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:oidc4vc/oidc4vc.dart';

void main() {
group('ClientAuthenticationX', () {
test('value', () {
expect(ClientAuthentication.none.value, 'none');
expect(
ClientAuthentication.clientSecretBasic.value, 'client_secret_basic');
expect(ClientAuthentication.clientSecretPost.value, 'client_secret_post');
expect(ClientAuthentication.clientId.value, 'client_id');
expect(ClientAuthentication.clientSecretJwt.value, 'client_secret_jwt');
});
});
}
12 changes: 12 additions & 0 deletions packages/oidc4vc/test/src/client_type_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:oidc4vc/oidc4vc.dart';

void main() {
group('ClientTypeX', () {
test('getTitle', () {
expect(ClientType.p256JWKThumprint.getTitle, 'P-256 JWK Thumbprint');
expect(ClientType.did.getTitle, 'DID');
expect(ClientType.confidential.getTitle, 'Confidential Client');
});
});
}
79 changes: 8 additions & 71 deletions packages/oidc4vc/test/src/const_values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,20 @@ const keyWithAlg = {
'alg': 'HS256',
};

const didKey = 'did:ebsi:zo9FR1YfAKFP3Q6dvqhxcXxnfeDiJDP97kmnqhyAUSACj';
const issuer = 'https://talao.co/issuer/zxhaokccsi';

const kid =
'''did:ebsi:zo9FR1YfAKFP3Q6dvqhxcXxnfeDiJDP97kmnqhyAUSACj#Cgcg1y9xj9uWFw56PMc29XBd9EReixzvnftBz8JwQFiB''';
const clientId =
'''did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9Kbrbpg5is8LfTLuQ1RsW5r7s7ZjbDDFbDgy1tLrdc7Bj3itBGQkuGUQyfzKhFqbUNW2PqJPMSSzWoF2DGSvDSijCtJtYCSRsjSVLrwu5oHNbnPFvSEC4iRZPpU6B6nExRBTa''';

const kid = '';

const ES256Alg = 'ES256';

const ES256KAlg = 'ES256K';

const HS256Alg = 'HS256';

const thumbprint = [
173,
150,
139,
1,
202,
186,
32,
132,
51,
6,
216,
230,
103,
154,
26,
196,
52,
23,
248,
132,
91,
7,
58,
174,
149,
38,
148,
157,
199,
122,
118,
36,
];
const thumbprint = 'rZaLAcq6IIQzBtjmZ5oaxDQX+IRbBzqulSaUncd6diQ';

const rfc7638Jwk = {
'e': 'AQAB',
Expand All @@ -83,37 +52,5 @@ const rfc7638Jwk = {
// ignore: lines_longer_than_80_chars
'0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw',
};
const expectedThumbprintForrfc7638Jwk = [
55,
54,
203,
177,
120,
124,
184,
48,
156,
119,
238,
140,
55,
5,
197,
225,
111,
251,
158,
133,
151,
21,
144,
31,
30,
76,
89,
177,
17,
130,
245,
123,
];
const expectedThumbprintForrfc7638Jwk =
'NzbLsXh8uDCcd+6MNwXF4W/7noWXFZAfHkxZsRGC9Xs';
21 changes: 21 additions & 0 deletions packages/oidc4vc/test/src/helper_function_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:oidc4vc/src/helper_function.dart';

void main() {
group('listToString', () {
test('converts list of strings to a single string with spaces', () {
final inputList = ['This', 'is', 'Bibash'];
expect(listToString(inputList), 'This is Bibash');
});

test('converts list of numbers to a single string with spaces', () {
final inputList = [1, 2, 3, 4];
expect(listToString(inputList), '1 2 3 4');
});

test('returns empty string for empty input list', () {
final inputList = <String>[];
expect(listToString(inputList), '');
});
});
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,66 @@
// import 'package:flutter_test/flutter_test.dart';
// import 'package:oidc4vc/oidc4vc.dart';

// import '../const_values.dart';
// import '../token_parameters/token_parameters_class.dart';

// class IssuerTokenParameterTest extends TokenParameterTest {
// final issuerTokenParameters = IssuerTokenParameters(privateKey, '', '', '');

// @override
// void publicKeyTest() {
// expect(issuerTokenParameters.publicJWK, publicJWK);
// }

// @override
// void didTest() {
// expect(tokenParameters.did, didKey);
// }

// @override
// void keyIdTest() {
// expect(tokenParameters.kid, kid);
// }

// @override
// void algorithmIsES256KTest() {
// expect(tokenParameters.alg, ES256KAlg);
// }

// @override
// void algorithmIsES256Test() {
// final tokenParameters = IssuerTokenParameters(privateKey2, '', '', '');
// expect(tokenParameters.alg, ES256Alg);
// }

// @override
// void algorithmIsNotNullTest() {
// final tokenParameters = IssuerTokenParameters(keyWithAlg, '', '', '');
// expect(tokenParameters.alg, HS256Alg);
// }
// }
import 'package:flutter_test/flutter_test.dart';
import 'package:oidc4vc/oidc4vc.dart';

import '../const_values.dart';
import '../token_parameters/token_parameters_class.dart';

class IssuerTokenParameterTest extends TokenParameterTest {
final issuerTokenParameters = IssuerTokenParameters(
privateKey: privateKey,
clientId: clientId,
did: clientId,
clientType: ClientType.did,
mediaType: MediaType.proofOfOwnership,
proofHeaderType: ProofHeaderType.kid,
issuer: issuer,
kid: '',
);

@override
void publicKeyTest() {
expect(issuerTokenParameters.publicJWK, publicJWK);
}

@override
void didTest() {
expect(tokenParameters.did, clientId);
}

@override
void keyIdTest() {
expect(tokenParameters.kid, kid);
}

@override
void algorithmIsES256KTest() {
expect(tokenParameters.alg, ES256KAlg);
}

@override
void algorithmIsES256Test() {
final tokenParameters = IssuerTokenParameters(
privateKey: privateKey2,
clientId: clientId,
did: clientId,
clientType: ClientType.did,
mediaType: MediaType.proofOfOwnership,
proofHeaderType: ProofHeaderType.kid,
issuer: issuer,
);
expect(tokenParameters.alg, ES256Alg);
}

@override
void algorithmIsNotNullTest() {
final tokenParameters = IssuerTokenParameters(
privateKey: keyWithAlg,
clientId: clientId,
did: clientId,
clientType: ClientType.did,
mediaType: MediaType.proofOfOwnership,
proofHeaderType: ProofHeaderType.kid,
issuer: issuer,
);
expect(tokenParameters.alg, HS256Alg);
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
// import 'package:flutter_test/flutter_test.dart';

// import 'issuer_token_parameters_class.dart';

// void main() {
// group('override test', () {
// final issuerTokenParameterTest = IssuerTokenParameterTest();

// // test(
// // 'public key is P-256K private key without d parameter',
// // issuerTokenParameterTest.publicKeyTest,
// // );

// // test('did EBSI', issuerTokenParameterTest.didTest);

// // test('kID EBSI', issuerTokenParameterTest.keyIdTest);

// group('algorithm test', () {
// test(
// "algorithm is ES256K when key's curve is not P-256",
// issuerTokenParameterTest.algorithmIsES256KTest,
// );

// test(
// "algorithm is ES256 when key's curve is P-256",
// issuerTokenParameterTest.algorithmIsES256Test,
// );

// test(
// 'if alg is not null then return as it is',
// issuerTokenParameterTest.algorithmIsNotNullTest,
// );
// });

// // group('thumbprint test', () {
// // test(
// // 'thumbprint of the public Key',
// // issuerTokenParameterTest.thumprintOfKey,
// // );

// // test(
// // 'thumbrprint of the Key from exemple in rfc 7638',
// // issuerTokenParameterTest.thumprintOfKeyForrfc7638,
// // );
// // });
// });
// }
import 'package:flutter_test/flutter_test.dart';

import 'issuer_token_parameters_class.dart';

void main() {
group('override test', () {
final issuerTokenParameterTest = IssuerTokenParameterTest();

test(
'public key is P-256K private key without d parameter',
issuerTokenParameterTest.publicKeyTest,
);

test('did EBSI', issuerTokenParameterTest.didTest);

test('kID EBSI', issuerTokenParameterTest.keyIdTest);

group('algorithm test', () {
test(
"algorithm is ES256K when key's curve is not P-256",
issuerTokenParameterTest.algorithmIsES256KTest,
);

test(
"algorithm is ES256 when key's curve is P-256",
issuerTokenParameterTest.algorithmIsES256Test,
);

test(
'if alg is not null then return as it is',
issuerTokenParameterTest.algorithmIsNotNullTest,
);
});

group('thumbprint test', () {
test(
'thumbprint of the public Key',
issuerTokenParameterTest.thumprintOfKey,
);

test(
'thumbrprint of the Key from exemple in rfc 7638',
issuerTokenParameterTest.thumprintOfKeyForrfc7638,
);
});
});
}
13 changes: 13 additions & 0 deletions packages/oidc4vc/test/src/media_type_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:oidc4vc/oidc4vc.dart';

void main() {
group('MediaTypeX', () {
test('typ', () {
expect(MediaType.proofOfOwnership.typ, 'openid4vci-proof+jwt');
expect(MediaType.basic.typ, 'JWT');
expect(MediaType.walletAttestation.typ, 'wiar+jwt');
expect(MediaType.selectiveDisclosure.typ, 'kb+jwt');
});
});
}
Loading

0 comments on commit 79c248e

Please sign in to comment.