Fix jwt-token
This commit is contained in:
@@ -65,9 +65,13 @@ describe('Security Tests', () => {
|
|||||||
// This might be valid depending on configuration
|
// This might be valid depending on configuration
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
expect.fail(`Token manipulation test "${test.name}" should have failed`);
|
// Token should have been rejected but wasn't - this is unexpected
|
||||||
|
throw new Error(`Token manipulation test "${test.name}" should have failed but was accepted`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Expected behavior - token should be rejected
|
// Expected behavior - token should be rejected
|
||||||
|
if (error.message && error.message.includes('should have failed but was accepted')) {
|
||||||
|
throw error; // Re-throw unexpected success
|
||||||
|
}
|
||||||
expect(error.name).to.be.oneOf(['JsonWebTokenError', 'TokenExpiredError', 'NotBeforeError']);
|
expect(error.name).to.be.oneOf(['JsonWebTokenError', 'TokenExpiredError', 'NotBeforeError']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,11 +234,15 @@ describe('Security Tests', () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
allowedIPs.forEach(ip => {
|
allowedIPs.forEach(ip => {
|
||||||
expect(checkIPRestriction(ip, tenant.ip_restrictions)).to.be.true;
|
const result = checkIPRestriction(ip, tenant.ip_restrictions);
|
||||||
|
console.log(`Testing allowed IP ${ip} against ${tenant.ip_restrictions}: ${result}`);
|
||||||
|
expect(result).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
blockedIPs.forEach(ip => {
|
blockedIPs.forEach(ip => {
|
||||||
expect(checkIPRestriction(ip, tenant.ip_restrictions)).to.be.false;
|
const result = checkIPRestriction(ip, tenant.ip_restrictions);
|
||||||
|
console.log(`Testing blocked IP ${ip} against ${tenant.ip_restrictions}: ${result}`);
|
||||||
|
expect(result).to.be.false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -147,8 +147,8 @@ async function createTestUser(userData = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaultUserData = {
|
const defaultUserData = {
|
||||||
username: 'testuser',
|
username: userData.username || `testuser${Date.now()}${Math.floor(Math.random() * 1000)}`,
|
||||||
email: 'test@example.com',
|
email: userData.email || `test${Date.now()}@example.com`,
|
||||||
password_hash: '$2b$10$dummyHashForTestingOnly',
|
password_hash: '$2b$10$dummyHashForTestingOnly',
|
||||||
role: 'admin',
|
role: 'admin',
|
||||||
tenant_id: tenant.id,
|
tenant_id: tenant.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user