diff --git a/test/utils/ethereumAddress.test.ts b/test/utils/ethereumAddress.test.ts index fdeffc5..d1010c1 100644 --- a/test/utils/ethereumAddress.test.ts +++ b/test/utils/ethereumAddress.test.ts @@ -11,7 +11,7 @@ describe("Ethereum Address Validation", () => { // Tests for the validateAddressFormat function (simple regex check) describe("validateAddressFormat", () => { // Should validate correct Ethereum address formats (regex only) - it("should validate correct address format", () => { + it("should return true for valid Ethereum address format (regex only)", () => { const validAddresses = [ "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", // Mixed case "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", // Lowercase @@ -26,7 +26,7 @@ describe("Ethereum Address Validation", () => { }); // Should reject invalid Ethereum address formats (regex only) - it("should reject invalid address formats", () => { + it("should return false for invalid Ethereum address formats (regex only)", () => { const invalidAddresses = [ "0x123", // Too short "not-an-address", // Not hex @@ -52,7 +52,7 @@ describe("Ethereum Address Validation", () => { // Tests for the isValidEthereumAddress function (checksum and format) describe("isValidEthereumAddress", () => { // Should validate correct Ethereum addresses, including checksummed, zero, and case-insensitive - it("should validate correct Ethereum addresses with checksum", () => { + it("should return true for valid Ethereum addresses (checksum, zero, case-insensitive)", () => { const validAddresses = [ // Valid checksummed addresses "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", @@ -72,7 +72,7 @@ describe("Ethereum Address Validation", () => { }); // Should reject invalid Ethereum addresses (bad format, prefix, or type) - it("should reject invalid Ethereum addresses", () => { + it("should return false for invalid Ethereum addresses (bad format, prefix, or type)", () => { const invalidAddresses = [ "0x123", // Too short "not-an-address", // Not hex @@ -101,7 +101,7 @@ describe("Ethereum Address Validation", () => { }); // Should handle edge cases (empty, null, undefined, non-string) - it("should handle edge cases correctly", () => { + it("should return false for edge cases (empty, null, undefined, non-string)", () => { // These should be invalid expect(isValidEthereumAddress("")).toBe(false); expect(isValidEthereumAddress("0x")).toBe(false); @@ -119,7 +119,7 @@ describe("Ethereum Address Validation", () => { // Comparison tests between validateAddressFormat and isValidEthereumAddress describe("Comparison between validation functions", () => { // Should show differences between simple regex and ethers.js validation - it("should show differences between simple regex and ethers validation", () => { + it("should compare simple regex and ethers.js validation for Ethereum addresses", () => { // Both functions should accept valid addresses const validAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; expect(validateAddressFormat(validAddress)).toBe(true); diff --git a/test/utils/generateApiKey.test.ts b/test/utils/generateApiKey.test.ts index 126b452..25a8855 100644 --- a/test/utils/generateApiKey.test.ts +++ b/test/utils/generateApiKey.test.ts @@ -17,7 +17,7 @@ describe('API Key Generation', () => { // Tests for the generateApiKey function describe('generateApiKey', () => { // Should generate a random API key of default length (32 bytes, 43 base64url chars) - it('should generate a random API key with default length', () => { + it('should generate a random API key of default length (32 bytes, 43 base64url chars)', () => { const apiKey = generateApiKey(); // Default length is 32 bytes, which is 43 characters in base64url expect(apiKey).toHaveLength(43); @@ -26,7 +26,7 @@ describe('API Key Generation', () => { }); // Should generate a random API key of custom byte length - it('should generate a random API key with custom length', () => { + it('should generate a random API key of custom byte length', () => { const length = 16; // 16 bytes const apiKey = generateApiKey(length); // 16 bytes is 22 characters in base64url (rounded up from 21.33) @@ -35,7 +35,7 @@ describe('API Key Generation', () => { }); // Should generate different keys on each call (randomness) - it('should generate different keys on each call', () => { + it('should generate different API keys on each call (randomness)', () => { const key1 = generateApiKey(); const key2 = generateApiKey(); expect(key1).not.toBe(key2); @@ -45,7 +45,7 @@ describe('API Key Generation', () => { // Tests for the generateUniqueApiKey function describe('generateUniqueApiKey', () => { // Should generate a unique API key with the default 'dv' prefix - it('should generate a unique API key with default prefix', () => { + it('should generate a unique API key with the default "dv" prefix', () => { const userId = '123456'; const apiKey = generateUniqueApiKey(userId); @@ -66,7 +66,7 @@ describe('API Key Generation', () => { }); // Should generate a unique API key with a custom prefix - it('should generate a unique API key with custom prefix', () => { + it('should generate a unique API key with a custom prefix', () => { const userId = '123456'; const prefix = 'test'; const apiKey = generateUniqueApiKey(userId, prefix); @@ -79,7 +79,7 @@ describe('API Key Generation', () => { }); // Should generate different keys for the same user (random part) - it('should generate different keys for the same user', () => { + it('should generate different unique API keys for the same user', () => { const userId = '123456'; const key1 = generateUniqueApiKey(userId); const key2 = generateUniqueApiKey(userId); @@ -90,7 +90,7 @@ describe('API Key Generation', () => { // Tests for the hashApiKey function describe('hashApiKey', () => { // Should hash an API key consistently (same input, same output) - it('should hash an API key consistently', () => { + it('should hash an API key consistently (same input, same output)', () => { const apiKey = 'dv_test_key'; const hash = hashApiKey(apiKey); @@ -104,7 +104,7 @@ describe('API Key Generation', () => { }); // Should produce different hashes for different API keys - it('should produce different hashes for different keys', () => { + it('should produce different hashes for different API keys', () => { const hash1 = hashApiKey('key1'); const hash2 = hashApiKey('key2'); expect(hash1).not.toBe(hash2); @@ -114,7 +114,7 @@ describe('API Key Generation', () => { // Tests for the maskApiKey function describe('maskApiKey', () => { // Should mask an API key, showing only the last 8 characters by default - it('should mask an API key with default visible characters', () => { + it('should mask an API key, showing only the last 8 characters by default', () => { const apiKey = 'dv_1234567890abcdefghijklmnopqrstuvwxyz'; const masked = maskApiKey(apiKey); @@ -125,7 +125,7 @@ describe('API Key Generation', () => { }); // Should mask an API key, showing a custom number of visible characters - it('should mask an API key with custom visible characters', () => { + it('should mask an API key, showing a custom number of visible characters', () => { const apiKey = 'dv_1234567890abcdefghijklmnopqrstuvwxyz'; const visibleChars = 4; const masked = maskApiKey(apiKey, visibleChars); @@ -137,7 +137,7 @@ describe('API Key Generation', () => { }); // Should handle short API keys (all masked if shorter than visible chars) - it('should handle short API keys', () => { + it('should handle short API keys (all masked if shorter than visible chars)', () => { const apiKey = 'short'; const masked = maskApiKey(apiKey, 8); @@ -150,7 +150,7 @@ describe('API Key Generation', () => { // Tests for the isValidApiKeyFormat function describe('isValidApiKeyFormat', () => { // Should validate correctly formatted API keys (prefix, timestamp, random part) - it('should validate correctly formatted API keys', () => { + it('should return true for correctly formatted API keys (prefix, timestamp, random part)', () => { // Generate a valid key with current timestamp const validKey = generateUniqueApiKey('test-user'); expect(isValidApiKeyFormat(validKey)).toBe(true); @@ -169,7 +169,7 @@ describe('API Key Generation', () => { }); // Should reject API keys with invalid format (missing parts, invalid chars, etc.) - it('should reject invalid API key formats', () => { + it('should return false for API keys with invalid format (missing parts, invalid chars, etc.)', () => { const invalidKeys = [ '', // Empty 'no_underscores', @@ -187,7 +187,7 @@ describe('API Key Generation', () => { }); // Should reject API keys with invalid or future timestamps - it('should reject keys with invalid timestamps', () => { + it('should return false for API keys with invalid or future timestamps', () => { const currentTimestamp = Date.now(); const futureTimestamp = (currentTimestamp + 1000000).toString(36); // Far future const invalidTimestampKeys = [ @@ -208,7 +208,7 @@ describe('API Key Generation', () => { // Tests for the generateMultipleApiKeys function describe('generateMultipleApiKeys', () => { // Should generate the requested number of API keys, all valid and unique - it('should generate the requested number of API keys', () => { + it('should generate the requested number of API keys, all valid and unique', () => { const count = 5; const userId = '123456'; const keys = generateMultipleApiKeys(count, userId); @@ -223,7 +223,7 @@ describe('API Key Generation', () => { }); // Should generate unique API keys in bulk - it('should generate unique keys', () => { + it('should generate unique API keys in bulk', () => { const count = 10; const userId = '123456'; const keys = generateMultipleApiKeys(count, userId); @@ -234,7 +234,7 @@ describe('API Key Generation', () => { }); // Should handle zero count (returns empty array) - it('should handle zero count', () => { + it('should return an empty array when count is zero', () => { const keys = generateMultipleApiKeys(0, '123456'); expect(keys).toHaveLength(0); }); diff --git a/test/utils/messageFormat.test.ts b/test/utils/messageFormat.test.ts index 7948888..52b83ad 100644 --- a/test/utils/messageFormat.test.ts +++ b/test/utils/messageFormat.test.ts @@ -6,7 +6,7 @@ describe('Message Format Validation', () => { const validSignature = '0x' + '1'.repeat(130); describe('Basic message validation', () => { - it('should accept valid plain text messages', () => { + it('should return valid for plain text messages', () => { const validMessages = [ 'Simple message', 'Message with numbers 123', @@ -27,7 +27,7 @@ describe('Message Format Validation', () => { }); }); - it('should accept messages with control characters (current implementation)', () => { + it('should return valid for messages with control characters (current implementation)', () => { const messagesWithControlChars = [ 'Message with newline\n', 'Message with tab\t', @@ -55,7 +55,7 @@ describe('Message Format Validation', () => { }); describe('Message content validation', () => { - it('should handle messages with JSON content', () => { + it('should return valid for messages with JSON content', () => { const jsonMessages = [ JSON.stringify({ action: 'login', timestamp: Date.now() }), JSON.stringify({ data: { userId: 123, role: 'admin' } }), @@ -74,7 +74,7 @@ describe('Message Format Validation', () => { }); }); - it('should handle messages with URL content', () => { + it('should return valid for messages with URL content', () => { const urlMessages = [ 'https://example.com', 'http://localhost:3000/api/auth?token=123', @@ -93,7 +93,7 @@ describe('Message Format Validation', () => { }); }); - it('should handle messages with timestamp content', () => { + it('should return valid for messages with timestamp content', () => { const timestampMessages = [ `Login request at ${Date.now()}`, `Verify my account: ${new Date().toISOString()}`, @@ -114,7 +114,7 @@ describe('Message Format Validation', () => { }); describe('Message security validation', () => { - it('should accept messages with potential XSS content (current implementation)', () => { + it('should return valid for messages with potential XSS content (current implementation)', () => { const xssMessages = [ '', 'javascript:alert("XSS")', @@ -137,7 +137,7 @@ describe('Message Format Validation', () => { }); - it('should accept messages with potential SQL injection content (current implementation)', () => { + it('should return valid for messages with potential SQL injection content (current implementation)', () => { const sqlInjectionMessages = [ "' OR '1'='1", "'; DROP TABLE users; --", diff --git a/test/utils/validation.test.ts b/test/utils/validation.test.ts index 1574c03..fdce660 100644 --- a/test/utils/validation.test.ts +++ b/test/utils/validation.test.ts @@ -3,7 +3,7 @@ import { validateWalletAuthInput, validateSignatureFormat, validateAddressFormat describe('Input Validation', () => { describe('validateWalletAuthInput', () => { - it('should validate correct input format', () => { + it('should return valid for correct wallet authentication input', () => { const validInput = { walletAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', message: 'Test message', @@ -14,7 +14,7 @@ describe('Input Validation', () => { expect(result.error).toBeUndefined(); }); - it('should reject non-object input', () => { + it('should reject non-object or primitive input (null, undefined, number, string, array, boolean)', () => { const inputs = [null, undefined, 42, 'string', [], true]; inputs.forEach(input => { const result = validateWalletAuthInput(input); @@ -23,7 +23,7 @@ describe('Input Validation', () => { }); }); - it('should reject missing required fields', () => { + it('should reject input missing one or more required fields', () => { const incompleteInputs = [ { message: 'test', signature: '0x' + '1'.repeat(130) }, { walletAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', signature: '0x' + '1'.repeat(130) }, @@ -37,7 +37,7 @@ describe('Input Validation', () => { }); }); - it('should reject invalid field types', () => { + it('should reject input where walletAddress, message, or signature are not strings', () => { const invalidTypeInputs = [ { walletAddress: 123, message: 'test', signature: '0x' + '1'.repeat(130) }, { walletAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', message: 42, signature: '0x' + '1'.repeat(130) }, @@ -51,7 +51,7 @@ describe('Input Validation', () => { }); }); - it('should reject invalid wallet address format', () => { + it('should reject input with invalid wallet address format', () => { const invalidAddresses = [ '123', // Too short 'not-an-address', // Not hex @@ -73,7 +73,7 @@ describe('Input Validation', () => { }); }); - it('should reject invalid signature format', () => { + it('should reject input with invalid signature format', () => { const invalidSignatures = [ '0x123', // Too short 'not-a-signature', // Not hex @@ -96,7 +96,7 @@ describe('Input Validation', () => { }); }); - it('should reject empty messages', () => { + it('should reject input with empty or whitespace-only message', () => { const input = { walletAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', message: '', @@ -116,7 +116,7 @@ describe('Input Validation', () => { expect(whitespaceResult.error).toBe('Message cannot be empty'); }); - it('should reject too long messages', () => { + it('should reject input with message exceeding 1000 characters', () => { const input = { walletAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', message: 'a'.repeat(1001), @@ -127,7 +127,7 @@ describe('Input Validation', () => { expect(result.error).toBe('Message too long (max 1000 characters)'); }); - it('should reject input with extra unexpected fields', () => { + it('should allow input with extra unexpected fields (ignored)', () => { const input = { walletAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', message: 'test', @@ -140,7 +140,7 @@ describe('Input Validation', () => { expect(result.error).toBeUndefined(); }); - it('should reject input with null fields', () => { + it('should reject input where fields are null', () => { const input = { walletAddress: null, message: null, @@ -151,7 +151,7 @@ describe('Input Validation', () => { expect(result.error).toBe('walletAddress, message, and signature must be strings'); }); - it('should reject input with nested objects as fields', () => { + it('should reject input where fields are nested objects', () => { const input = { walletAddress: { address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' }, message: { text: 'test' }, @@ -162,7 +162,7 @@ describe('Input Validation', () => { expect(result.error).toBe('walletAddress, message, and signature must be strings'); }); - it('should reject input with array as value for fields', () => { + it('should reject input where fields are arrays', () => { const input = { walletAddress: ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'], message: ['test'], @@ -173,7 +173,7 @@ describe('Input Validation', () => { expect(result.error).toBe('walletAddress, message, and signature must be strings'); }); - it('should reject deeply nested input object', () => { + it('should allow deeply nested input object as long as required fields are valid', () => { const input = { walletAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', message: 'test', @@ -188,12 +188,12 @@ describe('Input Validation', () => { }); describe('validateSignatureFormat', () => { - it('should validate correct signature format', () => { + it('should return true for valid Ethereum signature format', () => { const validSignature = '0x' + '1'.repeat(130); expect(validateSignatureFormat(validSignature)).toBe(true); }); - it('should reject invalid signature formats', () => { + it('should return false for invalid Ethereum signature formats', () => { const invalidSignatures = [ '0x123', // Too short 'not-a-signature', // Not hex @@ -211,7 +211,7 @@ describe('Input Validation', () => { }); describe('validateAddressFormat', () => { - it('should validate correct address format', () => { + it('should return true for valid Ethereum address format', () => { const validAddresses = [ '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', // Mixed case '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // Lowercase @@ -223,7 +223,7 @@ describe('Input Validation', () => { }); }); - it('should reject invalid address formats', () => { + it('should return false for invalid Ethereum address formats', () => { const invalidAddresses = [ '0x123', // Too short 'not-an-address', // Not hex diff --git a/test/utils/verifySignature.test.ts b/test/utils/verifySignature.test.ts index d53c5f6..839d1aa 100644 --- a/test/utils/verifySignature.test.ts +++ b/test/utils/verifySignature.test.ts @@ -24,7 +24,7 @@ describe("Basic Signature Verification", () => { * Test that a valid signature from a known wallet address is accepted. * This ensures the verifySignature function works for correct inputs. */ - it("should return true for a valid signature from a known wallet", async () => { + it("should return true for a valid signature from a known wallet address", async () => { // Create a wallet with a known private key for consistent testing const wallet = new ethers.Wallet( "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" @@ -45,7 +45,7 @@ describe("Basic Signature Verification", () => { * Test that invalid signatures (wrong message or wrong address) are rejected. * This checks that the function does not falsely validate incorrect signatures. */ - it("should return false for invalid signatures with wrong message or address", async () => { + it("should return false for invalid signatures (wrong message or wrong address)", async () => { // Create a wallet for signing const wallet = new ethers.Wallet( "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" @@ -81,7 +81,7 @@ describe("Basic Signature Verification", () => { * Test that the function is case-insensitive with respect to wallet addresses. * Ethereum addresses can be checksummed, lowercase, uppercase, or mixed case. */ - it("should handle case sensitivity correctly in wallet addresses", async () => { + it("should be case-insensitive for wallet addresses (mixed, lower, upper, checksum)", async () => { // Create a wallet for signing const wallet = new ethers.Wallet( "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" @@ -134,7 +134,7 @@ describe("Basic Signature Verification", () => { * Test signature verification with real-world Ethereum address formats. * Ensures compatibility with various address representations. */ - it("should work with real Ethereum wallet address formats", async () => { + it("should work with various real-world Ethereum wallet address formats", async () => { // Test with a well-known Ethereum address (Vitalik's public address) const realWallet = new ethers.Wallet( "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" @@ -160,7 +160,7 @@ describe("Basic Signature Verification", () => { * Test edge cases for signature recovery, such as invalid, empty, or too-short signatures. * Ensures the function fails gracefully for malformed input. */ - it("should handle signature recovery edge cases", async () => { + it("should return false for signature recovery edge cases (invalid, empty, too short)", async () => { const wallet = new ethers.Wallet( "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" ); @@ -198,7 +198,7 @@ describe("Timestamp Signature Verification", () => { * Test that timestamped signature verification is case-insensitive for wallet addresses. * This ensures robust handling of address formats in time-based checks. */ - it("should handle case sensitivity in wallet addresses with timestamp verification", async () => { + it("should be case-insensitive for wallet addresses in timestamped signature verification", async () => { const wallet = new ethers.Wallet( "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" ); @@ -231,7 +231,7 @@ describe("Timestamp Signature Verification", () => { * Test that recent (non-expired) timestamped signatures are accepted. * Ensures the function allows valid, timely signatures. */ - it("should validate recent timestamped signatures", async () => { + it("should return valid for recent (non-expired) timestamped signatures", async () => { const wallet = new ethers.Wallet( "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" ); @@ -254,7 +254,7 @@ describe("Timestamp Signature Verification", () => { * Test that expired timestamped signatures are rejected. * Ensures the function enforces expiration windows. */ - it("should reject expired timestamped signatures", async () => { + it("should return false for expired timestamped signatures", async () => { const wallet = new ethers.Wallet( "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" ); @@ -279,7 +279,7 @@ describe("Timestamp Signature Verification", () => { * Test that signatures with a future timestamp are rejected. * Prevents accepting signatures that are not yet valid. */ - it("should reject future timestamped signatures", async () => { + it("should return false for future timestamped signatures", async () => { const wallet = new ethers.Wallet( "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" ); @@ -308,7 +308,7 @@ describe("Address Validation", () => { * Test that valid Ethereum addresses (checksummed and lowercase) are accepted, * and invalid addresses (wrong length, non-hex, bad checksum, etc.) are rejected. */ - it("should validate Ethereum address formats correctly", () => { + it("should return true for valid Ethereum address formats and false for invalid ones", () => { // Valid addresses (ethers.js is strict about EIP-55 checksum) const validAddresses = [ "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", // Mixed case (EIP-55 checksum)