Skip to content

Commit 0a17eb6

Browse files
authored
Mitigate security warning from regex with env var (#283)
### Motivation and Context <!-- Thank you for your contribution to the chat-copilot repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> We have to security warning from Code scanning: https://github.com/microsoft/chat-copilot/security/code-scanning/14 https://github.com/microsoft/chat-copilot/security/code-scanning/15 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Replace regex with startsWith. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [Contribution Guidelines](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
1 parent d0d92bb commit 0a17eb6

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

webapp/tests/chat.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
13
/* eslint-disable testing-library/prefer-screen-queries */
24
import { test } from '@playwright/test';
35
import * as simpletests from './testsBasic';

webapp/tests/testsBasic.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
13
import { expect } from '@playwright/test';
24
import * as util from './utils';
35

webapp/tests/testsMultiuser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
13
import { expect } from '@playwright/test';
24
import * as util from './utils';
35

webapp/tests/testsPlanner.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
13
import { expect } from '@playwright/test';
2-
import * as util from './utils'
4+
import * as util from './utils';
35

46
/*
57
Summary: Tests if the Copilot Chat can use the Planner with the Klarna plugin,
68
to generate a plan and execute it. Klarna doesnt require any auth credentials.
79
*/
810
export async function klarnaTest(page) {
911
await util.loginAndCreateNewChat(page);
10-
12+
1113
// Enable Klarna
1214
const pluginIdentifierText = 'Klarna ShoppingKlarnaEnableSearch';
1315
await util.openPluginPopUp(page, pluginIdentifierText);
1416
await util.enablePluginAndClosePopUp(page);
15-
17+
1618
// Try using Klarna by sending a request to the bot and wait for the response.
17-
const klarnaQuery = "Can you get me a list of prices of surface notebooks?";
19+
const klarnaQuery = 'Can you get me a list of prices of surface notebooks?';
1820
await util.sendChatMessageAndWaitForResponse(page, klarnaQuery);
1921
await util.executePlanAndWaitForResponse(page);
2022

2123
// Expect the last message to be the bot's response.
2224
const chatHistoryItems = page.getByTestId(new RegExp('chat-history-item-*'));
2325
await expect(chatHistoryItems.last()).toHaveAttribute('data-username', 'Copilot');
24-
26+
2527
// Specifically accessing the us site of klarna so any results should have a dollar sign
2628
await expect(chatHistoryItems.last()).toContainText('$');
2729

@@ -40,16 +42,16 @@ export async function jiraTest(page) {
4042

4143
// Enable Jira
4244
await util.openPluginPopUp(page, 'JiraAtlassianEnableAuthorize');
43-
45+
4446
// Enter Auth Credentials and server url
4547
await page.locator('#plugin-email-input').fill(process.env.REACT_APP_TEST_JIRA_EMAIL as string);
4648
await page.locator('#plugin-pat-input').fill(process.env.REACT_APP_TEST_JIRA_ACCESS_TOKEN as string);
4749
await page.getByPlaceholder('Enter the server url').fill(process.env.REACT_APP_TEST_JIRA_SERVER_URL as string);
48-
50+
4951
await util.enablePluginAndClosePopUp(page);
50-
52+
5153
// Try using Jira by sending a request to the bot and wait for it to respond.
52-
const jiraQuery = "Can you Get Issue details about SKTES-1 from jira ?";
54+
const jiraQuery = 'Can you Get Issue details about SKTES-1 from jira ?';
5355
await util.sendChatMessageAndWaitForResponse(page, jiraQuery);
5456
await util.executePlanAndWaitForResponse(page);
5557

@@ -60,7 +62,7 @@ export async function jiraTest(page) {
6062

6163
var chatbotResponse = await util.getLastChatMessageContentsAsStringWHistory(page, chatHistoryItems);
6264
await util.disablePluginAndEvaluateResponse(page, jiraQuery, chatbotResponse);
63-
65+
6466
await util.postUnitTest(page);
6567
}
6668

@@ -70,19 +72,23 @@ to generate a plan and execute it. The Github plugin uses a PAT token for auth.
7072
*/
7173
export async function githubTest(page) {
7274
await util.loginAndCreateNewChat(page);
73-
75+
7476
// Enable Github
7577
await util.openPluginPopUp(page, 'GitHubMicrosoftEnableIntegrate');
76-
78+
7779
// Enter Auth Credentials and server url
7880
await page.locator('#plugin-pat-input').fill(process.env.REACT_APP_TEST_GITHUB_ACCESS_TOKEN as string);
79-
await page.getByPlaceholder('Enter the account owner of repository').fill(process.env.REACT_APP_TEST_GITHUB_ACCOUNT_OWNER as string);
80-
await page.getByPlaceholder('Enter the name of repository').fill(process.env.REACT_APP_TEST_GITHUB_REPOSITORY_NAME as string);
81-
81+
await page
82+
.getByPlaceholder('Enter the account owner of repository')
83+
.fill(process.env.REACT_APP_TEST_GITHUB_ACCOUNT_OWNER as string);
84+
await page
85+
.getByPlaceholder('Enter the name of repository')
86+
.fill(process.env.REACT_APP_TEST_GITHUB_REPOSITORY_NAME as string);
87+
8288
await util.enablePluginAndClosePopUp(page);
83-
89+
8490
// Try using Github by sending a request to the bot and wait for it to respond.
85-
const githubQuery = "List the 5 most recent open pull requests";
91+
const githubQuery = 'List the 5 most recent open pull requests';
8692
await util.sendChatMessageAndWaitForResponse(page, githubQuery);
8793
await util.executePlanAndWaitForResponse(page);
8894

@@ -94,4 +100,4 @@ export async function githubTest(page) {
94100
await util.disablePluginAndEvaluateResponse(page, githubQuery, chatbotResponse);
95101

96102
await util.postUnitTest(page);
97-
}
103+
}

webapp/tests/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function loginHelper(page, useraccount, password) {
1313
// Expect the page to contain a "Login" button.
1414
await page.getByTestId('signinButton').click();
1515
// Clicking the login button should redirect to the login page.
16-
await expect(page).toHaveURL(new RegExp(`${process.env.REACT_APP_AAD_AUTHORITY}.*`));
16+
await page.url().startsWith(process.env.REACT_APP_AAD_AUTHORITY);
1717
// Login with the test user.
1818
await page.getByPlaceholder('Email, phone, or Skype').click();
1919
await page.getByPlaceholder('Email, phone, or Skype').fill(useraccount as string);
@@ -36,7 +36,7 @@ export async function loginHelperAnotherUser(page, useraccount, password) {
3636
// Expect the page to contain a "Login" button.
3737
await page.getByRole('button').click();
3838
// Clicking the login button should redirect to the login page.
39-
await expect(page).toHaveURL(new RegExp(`${process.env.REACT_APP_AAD_AUTHORITY}.*`));
39+
await page.url().startsWith(process.env.REACT_APP_AAD_AUTHORITY);
4040
// Login with the another user account.
4141
await page.getByRole('button', { name: 'Use another account' }).click();
4242
await page.getByPlaceholder('Email, phone, or Skype').click();

0 commit comments

Comments
 (0)