Skip to content

Commit 5a88807

Browse files
AlexTugarevroboquat
authored andcommitted
[dashboard] fix host value for Git Integrations
if `:` is included, just the preview of the callback URL should be replaced with `_`, but not actual host value.
1 parent 31c4178 commit 5a88807

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { render, fireEvent, screen } from "@testing-library/react";
8+
import { GitIntegrationModal } from "./Integrations";
9+
10+
test.only("should update redirectURL preview", async () => {
11+
render(<GitIntegrationModal mode="new" userId="F00" />);
12+
13+
fireEvent.change(screen.getByLabelText(/Host/i), {
14+
target: { value: "gitlab.gitpod.io:80" },
15+
});
16+
const host = screen.getByLabelText(/Host/i);
17+
// screen.debug(host);
18+
expect((host as HTMLInputElement).value).toEqual("gitlab.gitpod.io:80");
19+
20+
const redirectURL = screen.getByLabelText(/Redirect/i);
21+
// screen.debug(redirectURL);
22+
expect((redirectURL as HTMLInputElement).value).toEqual("http://localhost/auth/gitlab.gitpod.io_80/callback");
23+
});

components/dashboard/src/settings/Integrations.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,11 @@ export function GitIntegrationModal(
517517
},
518518
) {
519519
const callbackUrl = (host: string) => {
520+
// Negative Lookahead (?!\/)
521+
// `\/` matches the character `/`
522+
// "https://foobar:80".replace(/:(?!\/)/, "_")
523+
// => 'https://foobar_80'
524+
host = host.replace(/:(?!\/)/, "_");
520525
const pathname = `/auth/${host}/callback`;
521526
return gitpodHostUrl.with({ pathname }).toString();
522527
};
@@ -643,12 +648,6 @@ export function GitIntegrationModal(
643648
newHostValue = host.replace("https://", "");
644649
}
645650

646-
// Negative Lookahead (?!\/)
647-
// `\/` matches the character `/`
648-
// "https://foobar:80".replace(/:(?!\/)/, "_")
649-
// => 'https://foobar_80'
650-
newHostValue = host.replace(/:(?!\/)/, "_");
651-
652651
setHost(newHostValue);
653652
setRedirectURL(callbackUrl(newHostValue));
654653
setErrorMessage(undefined);
@@ -798,7 +797,7 @@ export function GitIntegrationModal(
798797
Provider Host Name
799798
</label>
800799
<input
801-
name="hostName"
800+
id="hostName"
802801
disabled={mode === "edit" || type === "Bitbucket"}
803802
type="text"
804803
placeholder={getPlaceholderForIntegrationType(type)}
@@ -813,7 +812,7 @@ export function GitIntegrationModal(
813812
</label>
814813
<div className="w-full relative">
815814
<input
816-
name="redirectURL"
815+
id="redirectURL"
817816
disabled={true}
818817
readOnly={true}
819818
type="text"

0 commit comments

Comments
 (0)