-
Notifications
You must be signed in to change notification settings - Fork 8
Add ui test for Oauth (AST-89331) #1080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cx-elchanan-arbiv
wants to merge
18
commits into
main
Choose a base branch
from
feature/elchanan/add-ui-for-oauth-authentication-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3ec9706
Add ui test for Oauth (AST-89331)
cx-elchanan-arbiv 5d73860
revert oauth in comment
cx-elchanan-arbiv afd8fc5
fix login error messages are not disappearing
cx-elchanan-arbiv f0d517a
close server immediately if user cancels OAuth login
cx-elchanan-arbiv a6376b8
check
cx-elchanan-arbiv a57516d
fix ui test
cx-elchanan-arbiv 52f40c0
fix ui v2
cx-elchanan-arbiv 72f8494
Update 12.oauthAuthentication.test.ts
cx-elchanan-arbiv 8ebcbac
after cr add checks in test
cx-elchanan-arbiv 1145308
If not logged in, logged-in to check logout flow
cx-elchanan-arbiv 8f187d9
after cr Split into multiple tests
cx-elchanan-arbiv 3270b83
skip oauth tests
cx-elchanan-arbiv 3e96582
fix
cx-elchanan-arbiv b55d2f6
Merge branch 'main' into feature/elchanan/add-ui-for-oauth-authentica…
cx-elchanan-arbiv 91e70f9
revert oauth
cx-elchanan-arbiv 4723652
Merge branch 'main' into feature/elchanan/add-ui-for-oauth-authentica…
cx-elchanan-arbiv bba25a3
Add offline_access scope to OAuth request to maintain token validity …
cx-elchanan-arbiv 817250a
Update auth.js
cx-elchanan-arbiv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,158 @@ | ||
import { | ||
By, | ||
EditorView, | ||
VSBrowser, | ||
WebDriver, | ||
WebView, | ||
Workbench | ||
} from "vscode-extension-tester"; | ||
import { expect } from "chai"; | ||
import { retryTest, sleep } from "./utils/utils"; | ||
|
||
const CX_AUTHENTICATION_COMMAND = "ast-results.showAuth"; | ||
|
||
describe.skip("Checkmarx OAuth Authentication Tests", () => { | ||
let bench: Workbench; | ||
let driver: WebDriver; | ||
|
||
before(async function () { | ||
this.timeout(15000); | ||
bench = new Workbench(); | ||
driver = VSBrowser.instance.driver; | ||
}); | ||
|
||
after(async () => { | ||
await bench.executeCommand("ast-results.mockTokenTest"); | ||
await sleep(3000); | ||
await new EditorView().closeAllEditors(); | ||
}); | ||
|
||
it("should open OAuth authentication panel and verify logout/login flow", retryTest(async function () { | ||
await bench.executeCommand(CX_AUTHENTICATION_COMMAND); | ||
await sleep(5000); | ||
|
||
const editorView = new EditorView(); | ||
await editorView.openEditor("Checkmarx One Authentication"); | ||
|
||
const webView = new WebView(); | ||
await webView.switchToFrame(10000); | ||
|
||
let logoutElements = await webView.findWebElements(By.id("logoutButton")); | ||
const isLoggedIn = logoutElements.length > 0 && await logoutElements[0].isDisplayed(); | ||
|
||
if (!isLoggedIn) { | ||
await webView.switchBack(); | ||
await bench.executeCommand("ast-results.mockTokenTest"); | ||
await sleep(3000); | ||
await new EditorView().closeAllEditors(); | ||
await bench.executeCommand(CX_AUTHENTICATION_COMMAND); | ||
await sleep(3000); | ||
await new EditorView().openEditor("Checkmarx One Authentication"); | ||
await webView.switchToFrame(5000); | ||
logoutElements = await webView.findWebElements(By.id("logoutButton")); | ||
} | ||
|
||
logoutElements = await webView.findWebElements(By.id("logoutButton")); | ||
if (logoutElements.length > 0 && await logoutElements[0].isDisplayed()) { | ||
await webView.switchBack(); | ||
await webView.switchToFrame(5000); | ||
await logoutElements[0].click(); | ||
await webView.switchBack(); | ||
await sleep(3000); | ||
await handleLogoutConfirmation(driver); | ||
await webView.switchToFrame(5000); | ||
} | ||
|
||
const loginForm = await webView.findWebElements(By.id("loginForm")); | ||
expect(loginForm.length).to.be.greaterThan(0, "Login form should be visible when logged out"); | ||
}, 3)); | ||
|
||
it("should verify radio buttons exist", retryTest(async function () { | ||
const webView = new WebView(); | ||
await webView.switchToFrame(10000); | ||
|
||
const radioButtons = await webView.findWebElements(By.css("input[type='radio']")); | ||
expect(radioButtons.length).to.be.at.least(2, "Should have at least 2 radio buttons (OAuth and API Key)"); | ||
|
||
await webView.switchBack(); | ||
}, 3)); | ||
|
||
it("should verify OAuth form exists", retryTest(async function () { | ||
const webView = new WebView(); | ||
await webView.switchToFrame(10000); | ||
|
||
const oauthRadio = await webView.findWebElement(By.css("input[name='authMethod'][value='oauth']")); | ||
await driver.executeScript("arguments[0].click();", oauthRadio); | ||
await sleep(1000); | ||
|
||
const oauthForm = await webView.findWebElement(By.id("oauthForm")); | ||
expect(oauthForm).to.not.be.undefined; | ||
|
||
await webView.switchBack(); | ||
}, 3)); | ||
|
||
it("should verify OAuth form text labels", retryTest(async function () { | ||
const webView = new WebView(); | ||
await webView.switchToFrame(10000); | ||
|
||
const oauthForm = await webView.findWebElement(By.id("oauthForm")); | ||
const oauthFormText = await oauthForm.getText(); | ||
|
||
expect(oauthFormText).to.include("Checkmarx One Base URL:", "Base URL label should be present in OAuth form"); | ||
expect(oauthFormText).to.include("Tenant Name:", "Tenant Name label should be present in OAuth form"); | ||
|
||
await webView.switchBack(); | ||
}, 3)); | ||
|
||
it("should verify OAuth button disabled state", retryTest(async function () { | ||
const webView = new WebView(); | ||
await webView.switchToFrame(10000); | ||
|
||
const authButton = await webView.findWebElement(By.id("authButton")); | ||
const disabledAttr = await authButton.getAttribute("disabled"); | ||
expect(disabledAttr).to.equal("true", "Auth button should be disabled when OAuth fields are empty"); | ||
|
||
await webView.switchBack(); | ||
}, 3)); | ||
|
||
it("should verify API Key form text labels", retryTest(async function () { | ||
const webView = new WebView(); | ||
await webView.switchToFrame(10000); | ||
|
||
const apiKeyRadio = await webView.findWebElement(By.css("input[name='authMethod'][value='apiKey']")); | ||
await driver.executeScript("arguments[0].click();", apiKeyRadio); | ||
await sleep(1000); | ||
|
||
const apiKeyForm = await webView.findWebElement(By.id("apiKeyForm")); | ||
const apiKeyFormText = await apiKeyForm.getText(); | ||
|
||
expect(apiKeyFormText).to.include("Checkmarx One API Key:", "API Key label should be present in API Key form"); | ||
|
||
await webView.switchBack(); | ||
}, 3)); | ||
|
||
it("should verify API Key button disabled state", retryTest(async function () { | ||
const webView = new WebView(); | ||
await webView.switchToFrame(10000); | ||
|
||
const authButton = await webView.findWebElement(By.id("authButton")); | ||
const disabledAttr = await authButton.getAttribute("disabled"); | ||
expect(disabledAttr).to.equal("true", "Auth button should be disabled when API Key field is empty"); | ||
|
||
await webView.switchBack(); | ||
}, 3)); | ||
|
||
async function handleLogoutConfirmation(driver) { | ||
const notifications = await driver.findElements(By.className("notification-toast")); | ||
for (const notification of notifications) { | ||
const notificationText = await notification.getText(); | ||
if (notificationText.includes("Are you sure you want to log out?")) { | ||
const yesButton = await notification.findElement(By.css(".monaco-button")); | ||
await yesButton.click(); | ||
await sleep(2000); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
}); |
This file contains hidden or 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 |
---|---|---|
|
@@ -291,4 +291,4 @@ export class AuthenticationWebview { | |
} | ||
} | ||
} | ||
} | ||
} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.