Skip to content

Commit

Permalink
refactor: support github devtunnel (#11964)
Browse files Browse the repository at this point in the history
* refactor: support github devtunnel

* refactor: update test case
  • Loading branch information
xiaolang124 authored Jul 5, 2024
1 parent 3be35d7 commit 63d5abb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
14 changes: 11 additions & 3 deletions packages/fx-core/src/common/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,22 @@ export async function getSPFxToken(

// this function will be deleted after VS has added get dev tunnel and list dev tunnels API
const TunnelManagementUserAgent = { name: "Teams-Toolkit" };
export async function listDevTunnels(token: string): Promise<Result<Tunnel[], FxError>> {
export async function listDevTunnels(
token: string,
isGitHub = false
): Promise<Result<Tunnel[], FxError>> {
try {
const tunnelManagementClientImpl = new TunnelManagementHttpClient(
TunnelManagementUserAgent,
ManagementApiVersions.Version20230927preview,
() => {
const res = `Bearer ${token}`;
return Promise.resolve(res);
if (isGitHub === true) {
const res = `github client_id=a200baed193bb2088a6e ${token}`;
return Promise.resolve(res);
} else {
const res = `Bearer ${token}`;
return Promise.resolve(res);
}
}
);

Expand Down
14 changes: 14 additions & 0 deletions packages/fx-core/tests/common/tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,20 @@ projectId: 00000000-0000-0000-0000-000000000000`;
});
});

describe("listDevTunnels using github token", () => {
const sandbox = sinon.createSandbox();
afterEach(() => {
sandbox.restore();
});

it("should return an error when the API call fails", async () => {
const token = "test-token";

const result = await listDevTunnels(token, true);
chai.assert.isTrue(result.isErr());
});
});

describe("isUserCancelError()", () => {
it("should return true if error is UserCancelError", () => {
const error = new Error();
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/serverConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export default class ServerConnection implements IServerConnection {
const corrId = inputs.correlationId ? inputs.correlationId : "";
const res = await Correlator.runWithId(
corrId,
(params) => listDevTunnels(inputs.devTunnelToken),
(params) => listDevTunnels(inputs.devTunnelToken, inputs.isGitHub),
inputs
);
return standardizeResult(res);
Expand Down

0 comments on commit 63d5abb

Please sign in to comment.