-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(editor): Use BroadcastChannel instead of window.opener for OAuth …
…callback window (#9779)
- Loading branch information
Showing
6 changed files
with
68 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { CredentialsPage, CredentialsModal } from '../pages'; | ||
|
||
const credentialsPage = new CredentialsPage(); | ||
const credentialsModal = new CredentialsModal(); | ||
|
||
describe('Credentials', () => { | ||
it('create and connect with Google OAuth2', () => { | ||
// Open credentials page | ||
cy.visit(credentialsPage.url, { | ||
onBeforeLoad(win) { | ||
cy.stub(win, 'open').as('windowOpen'); | ||
}, | ||
}); | ||
|
||
// Add a new Google OAuth2 credential | ||
credentialsPage.getters.emptyListCreateCredentialButton().click(); | ||
credentialsModal.getters.newCredentialTypeOption('Google OAuth2 API').click(); | ||
credentialsModal.getters.newCredentialTypeButton().click(); | ||
|
||
// Fill in the key/secret and save | ||
credentialsModal.actions.fillField('clientId', 'test-key'); | ||
credentialsModal.actions.fillField('clientSecret', 'test-secret'); | ||
credentialsModal.actions.save(); | ||
|
||
// Connect to Google | ||
credentialsModal.getters.oauthConnectButton().click(); | ||
cy.get('@windowOpen').should( | ||
'have.been.calledOnceWith', | ||
Cypress.sinon.match( | ||
'https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=consent&client_id=test-key&redirect_uri=http%3A%2F%2Flocalhost%3A5678%2Frest%2Foauth2-credential%2Fcallback&response_type=code', | ||
), | ||
'OAuth Authorization', | ||
'scrollbars=no,resizable=yes,status=no,titlebar=noe,location=no,toolbar=no,menubar=no,width=500,height=700', | ||
); | ||
|
||
// Emulate successful save using BroadcastChannel | ||
cy.window().then(() => { | ||
const channel = new BroadcastChannel('oauth-callback'); | ||
channel.postMessage('success'); | ||
}); | ||
|
||
// Check that the credential was saved and connected successfully | ||
credentialsModal.getters.saveButton().should('contain.text', 'Saved'); | ||
credentialsModal.getters.oauthConnectSuccessBanner().should('be.visible'); | ||
}); | ||
}); |
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