Skip to content

Commit 9316a9a

Browse files
committed
add simple conversion tests for auth providers
1 parent 9dbe696 commit 9316a9a

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

components/gitpod-protocol/src/public-api-converter.spec.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ import {
2121
PrebuildSettings,
2222
WorkspaceSettings,
2323
} from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
24+
import { AuthProviderEntry, AuthProviderInfo } from "./protocol";
25+
import {
26+
AuthProvider,
27+
AuthProviderDescription,
28+
AuthProviderType,
29+
} from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
2430

2531
describe("PublicAPIConverter", () => {
2632
const converter = new PublicAPIConverter();
@@ -721,4 +727,80 @@ describe("PublicAPIConverter", () => {
721727
expect(result).to.deep.equal(new WorkspaceSettings());
722728
});
723729
});
730+
731+
describe("toAuthProviderDescription", () => {
732+
const info: AuthProviderInfo = {
733+
authProviderId: "ap123",
734+
authProviderType: "GitHub",
735+
host: "localhost",
736+
verified: true,
737+
icon: "unused icon",
738+
description: "unused description",
739+
settingsUrl: "unused",
740+
ownerId: "unused",
741+
organizationId: "unused",
742+
};
743+
const description = new AuthProviderDescription({
744+
id: info.authProviderId,
745+
type: AuthProviderType.GITHUB,
746+
host: info.host,
747+
icon: info.icon,
748+
description: info.description,
749+
});
750+
it("should convert an auth provider info to a description", () => {
751+
const result = converter.toAuthProviderDescription(info);
752+
expect(result).to.deep.equal(description);
753+
});
754+
});
755+
756+
describe("toAuthProvider", () => {
757+
const entry: AuthProviderEntry = {
758+
id: "ap123",
759+
type: "GitHub",
760+
host: "localhost",
761+
status: "pending",
762+
ownerId: "userId",
763+
organizationId: "orgId123",
764+
oauth: {
765+
clientId: "clientId123",
766+
clientSecret: "should not appear in result",
767+
callBackUrl: "localhost/callback",
768+
authorizationUrl: "auth.service/authorize",
769+
tokenUrl: "auth.service/token",
770+
},
771+
};
772+
const provider = new AuthProvider({
773+
id: entry.id,
774+
type: AuthProviderType.GITHUB,
775+
host: entry.host,
776+
oauth2Config: {
777+
clientId: entry.oauth?.clientId,
778+
clientSecret: entry.oauth?.clientSecret,
779+
},
780+
owner: {
781+
case: "organizationId",
782+
value: entry.organizationId!,
783+
},
784+
});
785+
it("should convert an auth provider", () => {
786+
const result = converter.toAuthProvider(entry);
787+
expect(result).to.deep.equal(provider);
788+
});
789+
});
790+
791+
describe("toAuthProviderType", () => {
792+
const mapping: { [key: string]: number } = {
793+
GitHub: AuthProviderType.GITHUB,
794+
GitLab: AuthProviderType.GITLAB,
795+
Bitbucket: AuthProviderType.BITBUCKET,
796+
BitbucketServer: AuthProviderType.BITBUCKET_SERVER,
797+
Other: AuthProviderType.UNSPECIFIED,
798+
};
799+
it("should convert auth provider types", () => {
800+
for (const k of Object.getOwnPropertyNames(mapping)) {
801+
const result = converter.toAuthProviderType(k);
802+
expect(result).to.deep.equal(mapping[k]);
803+
}
804+
});
805+
});
724806
});

components/gitpod-protocol/src/public-api-converter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ export class PublicAPIConverter {
440440
const result = new AuthProviderDescription({
441441
id: ap.authProviderId,
442442
host: ap.host,
443+
description: ap.description,
444+
icon: ap.icon,
443445
type: this.toAuthProviderType(ap.authProviderType),
444446
});
445447
return result;

0 commit comments

Comments
 (0)