Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions test/utils/ethereumAddress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
34 changes: 17 additions & 17 deletions test/utils/generateApiKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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',
Expand All @@ -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 = [
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
});
Expand Down
14 changes: 7 additions & 7 deletions test/utils/messageFormat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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' } }),
Expand All @@ -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',
Expand All @@ -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()}`,
Expand All @@ -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 = [
'<script>alert("XSS")</script>',
'javascript:alert("XSS")',
Expand All @@ -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; --",
Expand Down
Loading