Skip to content

Commit

Permalink
LENSCLOUD-160: user auth method (#556)
Browse files Browse the repository at this point in the history
LENSCLOUD-160: user auth method
  • Loading branch information
ghkadim authored Jul 23, 2024
1 parent 25de732 commit 55a0c5a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
10 changes: 5 additions & 5 deletions integration-test/DemoClusterService.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ForbiddenException } from "../src";
import { config } from "./configuration";
import { testPlatformFactory } from "./utils";
import type { TestPlatform } from "./utils";
Expand All @@ -13,11 +14,10 @@ describe("DemoClusterService", () => {
});

describe("getConfig", () => {
it("returns kubeconfig file", async () => {
const config = await bobPlatform.client.demoCluster.getConfig();

expect(config.startsWith("apiVersion: v1")).toBeTruthy();
expect(typeof config).toBe("string");
it("doesn't return democluster config for old users", async () => {
return expect(bobPlatform.client.demoCluster.getConfig()).rejects.toThrowError(
ForbiddenException,
);
});
});
});
15 changes: 15 additions & 0 deletions src/User.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { minimumOptions as options, apiEndpointAddress } from "./LensPlatformCli

describe(".user.*", () => {
const username = "test-username";
const email = "test@example.com";

nock(apiEndpointAddress)
.get("/users")
Expand Down Expand Up @@ -39,6 +40,11 @@ describe(".user.*", () => {
onboarding: false,
});

nock(apiEndpointAddress).get(`/users/${email}/auth-method`).reply(200, {
method: "sso",
identityProviderID: "provider-id",
});

const lensPlatformClient = new LensPlatformClient(options);

lensPlatformClient.getDecodedAccessToken = jest.fn().mockResolvedValue({
Expand Down Expand Up @@ -133,4 +139,13 @@ describe(".user.*", () => {

expect(response).toBeUndefined();
});

it("should get sso auth method", async () => {
const response = await lensPlatformClient.user.getAuthMethod(email);

expect(response).toEqual({
method: "sso",
identityProviderID: "provider-id",
});
});
});
15 changes: 15 additions & 0 deletions src/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ export interface LinkedUserAccount {
username: string | undefined;
}

export interface UserAuthMethod {
method: "sso" | "password" | "google" | "github" | "apple";
identityProviderID?: string;
}

/**
*
* The class for consuming all `user` resources.
Expand Down Expand Up @@ -878,6 +883,16 @@ class UserService extends Base {

return username ?? "";
}

async getAuthMethod(email: string) {
const { apiEndpointAddress, fetch } = this.lensPlatformClient;
const url = `${apiEndpointAddress}/users/${email}/auth-method`;
const json = await throwExpected(async () => fetch.get(url), {
404: (error) => new NotFoundException(error?.body?.message),
});

return json as unknown as UserAuthMethod;
}
}

export { UserService };

0 comments on commit 55a0c5a

Please sign in to comment.