Skip to content

Commit

Permalink
[dashboard] fix host value for Git Integrations
Browse files Browse the repository at this point in the history
if `:` is included, just the preview of the callback URL should be replaced with `_`, but not actual host value.
  • Loading branch information
AlexTugarev authored and roboquat committed Aug 9, 2022
1 parent 31c4178 commit 5a88807
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
23 changes: 23 additions & 0 deletions components/dashboard/src/settings/Integrations.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

import { render, fireEvent, screen } from "@testing-library/react";
import { GitIntegrationModal } from "./Integrations";

test.only("should update redirectURL preview", async () => {
render(<GitIntegrationModal mode="new" userId="F00" />);

fireEvent.change(screen.getByLabelText(/Host/i), {
target: { value: "gitlab.gitpod.io:80" },
});
const host = screen.getByLabelText(/Host/i);
// screen.debug(host);
expect((host as HTMLInputElement).value).toEqual("gitlab.gitpod.io:80");

const redirectURL = screen.getByLabelText(/Redirect/i);
// screen.debug(redirectURL);
expect((redirectURL as HTMLInputElement).value).toEqual("http://localhost/auth/gitlab.gitpod.io_80/callback");
});
15 changes: 7 additions & 8 deletions components/dashboard/src/settings/Integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ export function GitIntegrationModal(
},
) {
const callbackUrl = (host: string) => {
// Negative Lookahead (?!\/)
// `\/` matches the character `/`
// "https://foobar:80".replace(/:(?!\/)/, "_")
// => 'https://foobar_80'
host = host.replace(/:(?!\/)/, "_");
const pathname = `/auth/${host}/callback`;
return gitpodHostUrl.with({ pathname }).toString();
};
Expand Down Expand Up @@ -643,12 +648,6 @@ export function GitIntegrationModal(
newHostValue = host.replace("https://", "");
}

// Negative Lookahead (?!\/)
// `\/` matches the character `/`
// "https://foobar:80".replace(/:(?!\/)/, "_")
// => 'https://foobar_80'
newHostValue = host.replace(/:(?!\/)/, "_");

setHost(newHostValue);
setRedirectURL(callbackUrl(newHostValue));
setErrorMessage(undefined);
Expand Down Expand Up @@ -798,7 +797,7 @@ export function GitIntegrationModal(
Provider Host Name
</label>
<input
name="hostName"
id="hostName"
disabled={mode === "edit" || type === "Bitbucket"}
type="text"
placeholder={getPlaceholderForIntegrationType(type)}
Expand All @@ -813,7 +812,7 @@ export function GitIntegrationModal(
</label>
<div className="w-full relative">
<input
name="redirectURL"
id="redirectURL"
disabled={true}
readOnly={true}
type="text"
Expand Down

0 comments on commit 5a88807

Please sign in to comment.