forked from danny-avila/LibreChat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔒✉️ feat: allow only certain domain (danny-avila#1562)
* feat: allow only certain domain * Update dotenv.md * refactor( registrationController) & handle ALLOWED_REGISTRATION_DOMAINS not specified * cleanup and moved to AuthService for better error handling * refactor: replace environment variable with librechat config item, add typedef for custom config, update docs for new registration object and allowedDomains values * ci(AuthService): test for `isDomainAllowed` --------- Co-authored-by: Danny Avila <messagedaniel@protonmail.com>
- Loading branch information
1 parent
9361afc
commit 4c62c5b
Showing
8 changed files
with
136 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const getCustomConfig = require('~/cache/getCustomConfig'); | ||
const { isDomainAllowed } = require('./AuthService'); | ||
|
||
jest.mock('~/cache/getCustomConfig', () => jest.fn()); | ||
|
||
describe('isDomainAllowed', () => { | ||
it('should allow domain when customConfig is not available', async () => { | ||
getCustomConfig.mockResolvedValue(null); | ||
await expect(isDomainAllowed('test@domain1.com')).resolves.toBe(true); | ||
}); | ||
|
||
it('should allow domain when allowedDomains is not defined in customConfig', async () => { | ||
getCustomConfig.mockResolvedValue({}); | ||
await expect(isDomainAllowed('test@domain1.com')).resolves.toBe(true); | ||
}); | ||
|
||
it('should reject an email if it is falsy', async () => { | ||
getCustomConfig.mockResolvedValue({}); | ||
await expect(isDomainAllowed('')).resolves.toBe(false); | ||
}); | ||
|
||
it('should allow a domain if it is included in the allowedDomains', async () => { | ||
getCustomConfig.mockResolvedValue({ | ||
registration: { | ||
allowedDomains: ['domain1.com', 'domain2.com'], | ||
}, | ||
}); | ||
await expect(isDomainAllowed('user@domain1.com')).resolves.toBe(true); | ||
}); | ||
|
||
it('should reject a domain if it is not included in the allowedDomains', async () => { | ||
getCustomConfig.mockResolvedValue({ | ||
registration: { | ||
allowedDomains: ['domain1.com', 'domain2.com'], | ||
}, | ||
}); | ||
await expect(isDomainAllowed('user@domain3.com')).resolves.toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters