Implemented desktop OAuth2 account setup for Google and Microsoft. The flow uses the system browser and PKCE; access and refresh tokens stay in the main process and encrypted account store. OAuth connections use fixed provider endpoints, and existing password-based accounts remain supported. Android remains password-based in this phase.
This commit is contained in:
@@ -43,6 +43,34 @@ test('rejects invalid account fields and malformed mail rules', () => {
|
||||
}), /must move messages/);
|
||||
});
|
||||
|
||||
test('normalizes OAuth2 accounts to provider servers without requiring a password', () => {
|
||||
const google = normalizeAccount({
|
||||
email: 'user@gmail.com', authMethod: 'oauth2', oauthProvider: 'google', displayName: 'User'
|
||||
});
|
||||
assert.equal(google.password, '');
|
||||
assert.equal(google.authMethod, 'oauth2');
|
||||
assert.equal(google.oauthProvider, 'google');
|
||||
assert.equal(google.imapHost, 'imap.gmail.com');
|
||||
assert.equal(google.imapPort, 993);
|
||||
assert.equal(google.imapSecure, true);
|
||||
assert.equal(google.smtpHost, 'smtp.gmail.com');
|
||||
const untrustedEndpoints = normalizeAccount({
|
||||
email: 'user@gmail.com', authMethod: 'oauth2', oauthProvider: 'google', displayName: 'User',
|
||||
imapHost: 'attacker.example.test', smtpHost: 'attacker.example.test', imapPort: 143
|
||||
});
|
||||
assert.equal(untrustedEndpoints.imapHost, 'imap.gmail.com');
|
||||
assert.equal(untrustedEndpoints.smtpHost, 'smtp.gmail.com');
|
||||
assert.equal(untrustedEndpoints.imapPort, 993);
|
||||
|
||||
const microsoft = normalizeAccount({
|
||||
email: 'user@outlook.com', authMethod: 'oauth2', oauthProvider: 'microsoft', displayName: 'User'
|
||||
});
|
||||
assert.equal(microsoft.imapHost, 'outlook.office365.com');
|
||||
assert.equal(microsoft.smtpHost, 'smtp.office365.com');
|
||||
assert.throws(() => normalizeAccount({ email: 'user@example.test', authMethod: 'oauth2', displayName: 'User' }), /Choose Google or Microsoft/);
|
||||
assert.throws(() => normalizeAccount({ email: 'user@example.test', authMethod: 'oauth', password: 'secret', displayName: 'User' }), /supported sign-in method/);
|
||||
});
|
||||
|
||||
test('public account projection does not expose the password or private mailbox state', () => {
|
||||
const account = normalizeAccount(accountInput);
|
||||
const result = publicAccount({
|
||||
@@ -54,6 +82,8 @@ test('public account projection does not expose the password or private mailbox
|
||||
assert.equal(result.id, 'account-1');
|
||||
assert.equal(result.email, 'user@example.com');
|
||||
assert.equal('password' in result, false);
|
||||
assert.equal('oauthRefreshToken' in result, false);
|
||||
assert.equal('oauthAccessToken' in result, false);
|
||||
assert.equal('drafts' in result, false);
|
||||
assert.equal('mailOutbox' in result, false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user