Add baseline unit tests and fix home server normalization
This commit is contained in:
1 parent
a93d619b4c
commit
ce7c97d13a
6 files changed
+227
-8
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import 'package:chat_server/src/auth/crypto_service.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('AuthService password hashing', () {
|
||||
test('hash + verify works', () {
|
||||
const password = 'pass1234';
|
||||
final hash = AuthService.hashPassword(password);
|
||||
|
||||
expect(hash, isNotEmpty);
|
||||
expect(AuthService.verifyPassword(password, hash), isTrue);
|
||||
expect(AuthService.verifyPassword('wrong-password', hash), isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
group('CryptoService signing', () {
|
||||
test('signatures verify with matching keypair', () {
|
||||
final keyPair = CryptoService.generateKeyPair();
|
||||
const payload = 'alice@localhost:9870:1700000000';
|
||||
|
||||
final signature = CryptoService.sign(payload, keyPair.privateKey);
|
||||
final ok = CryptoService.verify(payload, signature, keyPair.publicKey);
|
||||
|
||||
expect(ok, isTrue);
|
||||
});
|
||||
|
||||
test('signature fails for modified payload', () {
|
||||
final keyPair = CryptoService.generateKeyPair();
|
||||
const payload = 'payload-a';
|
||||
const tamperedPayload = 'payload-b';
|
||||
|
||||
final signature = CryptoService.sign(payload, keyPair.privateKey);
|
||||
final ok = CryptoService.verify(
|
||||
tamperedPayload,
|
||||
signature,
|
||||
keyPair.publicKey,
|
||||
);
|
||||
|
||||
expect(ok, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user