Skip to content
Snippets Groups Projects
Commit 3e4c2a53 authored by vjrj's avatar vjrj
Browse files

Fix pubkey regexp

parent b9d3c341
No related branches found
No related tags found
No related merge requests found
...@@ -98,7 +98,7 @@ String? parseHost(String endpointUnParsed) { ...@@ -98,7 +98,7 @@ String? parseHost(String endpointUnParsed) {
bool validateKey(String pubKey) { bool validateKey(String pubKey) {
return RegExp( return RegExp(
r'^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{44}$') r'^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{43,44}$')
.hasMatch(pubKey); .hasMatch(pubKey);
} }
......
import 'dart:convert';
import 'dart:typed_data';
import 'package:durt/durt.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ginkgo/data/models/payment_state.dart';
import 'package:ginkgo/g1/g1_helper.dart';
void main() {
test('Test serialization and deserialization of UInt8List seeds', () {
final Uint8List seed = generateUintSeed();
final String sSeed = seedToString(seed);
final Uint8List seedRestored = seedFromString(sSeed);
expect(seed, equals(seedRestored));
final CesiumWallet wallet = generateCesiumWallet(seed);
final CesiumWallet walletRestored = generateCesiumWallet(seedRestored);
expect(wallet.pubkey, equals(walletRestored.pubkey));
expect(wallet.seed, equals(walletRestored.seed));
expect(wallet.rootKey, equals(walletRestored.rootKey));
});
test('parse different networks/peers BMAS', () {
expect(
parseHost('BMAS g1.texu.es 7443'), equals('https://g1.texu.es:7443'));
expect(
parseHost('BMAS g1.duniter.org 443'), equals('https://g1.duniter.org'));
expect(parseHost('BMAS g1.leprette.fr 443 /bma'),
equals('https://g1.leprette.fr/bma'));
expect(parseHost('BMAS g1-vijitatman.es 212.227.41.252 443'),
equals('https://g1-vijitatman.es'));
expect(
parseHost(
'BMAS monnaie-libre.ortie.org/bma/ 192.168.1.35 2a01:cb0d:5c2:fa00:21e:68ff:feab:389a 443'),
equals('https://monnaie-libre.ortie.org/bma'));
});
test('parse different networks/peers GVA S', () {
expect(parseHost('GVA S duniter.master.aya.autissier.net 443 gva'),
equals('https://duniter.master.aya.autissier.net/gva'));
});
test('validate pub keys', () {
expect(validateKey('FRYyk57Pi456EJRu9vqVfSHLgmUfx4Qc3goS62a7dUSm'),
equals(true));
expect(validateKey('BrgsSYK3xUzDyztGBHmxq69gfNxBfe2UKpxG21oZUBr5'),
equals(true));
expect(validateKey('naU6XunXd1LSSfsHu3aNk8ZqgSosKQcvEQz8F2KaRAy'),
equals(true));
});
test('validate qr uris', () {
const String publicKey = 'FRYyk57Pi456EJRu9vqVfSHLgmUfx4Qc3goS62a7dUSm';
final String uriA = getQrUri(publicKey, '10');
final PaymentState? payA = parseScannedUri(uriA);
expect(payA!.amount, equals(10));
expect(payA.contact!.pubKey, equals(publicKey));
final String uriB = getQrUri(publicKey);
final PaymentState? payB = parseScannedUri(uriB);
expect(payB!.amount, equals(null));
expect(payB.contact!.pubKey, equals(publicKey));
final PaymentState? payC = parseScannedUri(publicKey);
expect(payC!.amount, equals(null));
expect(payC.contact!.pubKey, equals(publicKey));
});
test('encrypt/decrypt of keys', () {
const String pass = '1234';
const String wrongPass = '1235';
final Map<String, String> sample = <String, String>{
'public': 'some public',
'private': 'some private'
};
final Map<String, String> encSample =
encryptJsonForExport(jsonEncode(sample), pass);
final String encJson = encSample['key']!;
expect(encJson.isNotEmpty, equals(true));
final Map<String, dynamic> decrypted = decryptJsonForImport(encJson, pass);
expect(decrypted['public'], equals('some public'));
expect(decrypted['private'], equals('some private'));
try {
// test wrong pass
decryptJsonForImport(encJson, wrongPass);
} catch (e) {
expect(e, isArgumentError);
}
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment