refactor: Rename CSP to Cloud
Signed-off-by: Carlos Esteban Lopez <lcarlosesteb@vmware.com>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# Auth Module: VMware Cloud Provider
|
||||
|
||||
This module provides an VMware Cloud auth provider implementation for `@backstage/plugin-auth-backend`.
|
||||
|
||||
## Links
|
||||
|
||||
- [Backstage](https://backstage.io)
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@backstage/plugin-auth-backend-module-vmware-csp-provider",
|
||||
"description": "The vmware-csp-provider backend module for the auth plugin.",
|
||||
"name": "@backstage/plugin-auth-backend-module-vmware-cloud-provider",
|
||||
"description": "The vmware-cloud-provider backend module for the auth plugin.",
|
||||
"version": "0.0.0",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
+44
-36
@@ -29,8 +29,8 @@ import { http, HttpResponse } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
|
||||
import {
|
||||
vmWareCSPAuthenticator,
|
||||
vmWareCSPAuthenticatorContext,
|
||||
vmwareCloudAuthenticator,
|
||||
vmwareCloudAuthenticatorContext,
|
||||
} from './authenticator';
|
||||
|
||||
jest.mock('uid2', () => jest.fn().mockReturnValue('sessionid'));
|
||||
@@ -60,7 +60,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
};
|
||||
|
||||
let fakeSession: Record<string, any>;
|
||||
let authenticatorCtx: vmWareCSPAuthenticatorContext;
|
||||
let authenticatorCtx: vmwareCloudAuthenticatorContext;
|
||||
|
||||
beforeAll(async () => {
|
||||
idToken = await new SignJWT(signInInfo)
|
||||
@@ -85,7 +85,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
),
|
||||
);
|
||||
|
||||
authenticatorCtx = vmWareCSPAuthenticator.initialize({
|
||||
authenticatorCtx = vmwareCloudAuthenticator.initialize({
|
||||
callbackUrl: 'http://callbackUrl',
|
||||
config: new ConfigReader({
|
||||
clientId: 'placeholderClientId',
|
||||
@@ -97,7 +97,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
describe('#initialize', () => {
|
||||
it('fails when organizationId is not configured', () => {
|
||||
return expect(() =>
|
||||
vmWareCSPAuthenticator.initialize({
|
||||
vmwareCloudAuthenticator.initialize({
|
||||
callbackUrl: 'http://callbackUrl',
|
||||
config: new ConfigReader({
|
||||
clientId: 'placeholderClientId',
|
||||
@@ -122,7 +122,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('redirects to the Cloud Services Console consent page', async () => {
|
||||
const startResponse = await vmWareCSPAuthenticator.start(
|
||||
const startResponse = await vmwareCloudAuthenticator.start(
|
||||
startRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
@@ -134,7 +134,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('passes client ID from config', async () => {
|
||||
const startResponse = await vmWareCSPAuthenticator.start(
|
||||
const startResponse = await vmwareCloudAuthenticator.start(
|
||||
startRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
@@ -144,7 +144,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('passes organizationId from config', async () => {
|
||||
const startResponse = await vmWareCSPAuthenticator.start(
|
||||
const startResponse = await vmwareCloudAuthenticator.start(
|
||||
startRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
@@ -154,7 +154,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('passes callback URL', async () => {
|
||||
const startResponse = await vmWareCSPAuthenticator.start(
|
||||
const startResponse = await vmwareCloudAuthenticator.start(
|
||||
startRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
@@ -164,7 +164,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('requests scopes for ID and refresh token', async () => {
|
||||
const startResponse = await vmWareCSPAuthenticator.start(
|
||||
const startResponse = await vmwareCloudAuthenticator.start(
|
||||
startRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
@@ -174,7 +174,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('generates PKCE challenge', async () => {
|
||||
const startResponse = await vmWareCSPAuthenticator.start(
|
||||
const startResponse = await vmwareCloudAuthenticator.start(
|
||||
startRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
@@ -185,7 +185,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('stores PKCE verifier in session', async () => {
|
||||
await vmWareCSPAuthenticator.start(startRequest, authenticatorCtx);
|
||||
await vmwareCloudAuthenticator.start(startRequest, authenticatorCtx);
|
||||
|
||||
expect(
|
||||
fakeSession['oauth2:console.cloud.vmware.com'].state.code_verifier,
|
||||
@@ -194,7 +194,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
|
||||
it('fails when request has no session', () => {
|
||||
return expect(
|
||||
vmWareCSPAuthenticator.start(
|
||||
vmwareCloudAuthenticator.start(
|
||||
{
|
||||
state: encodeOAuthState(oAuthState),
|
||||
req: {
|
||||
@@ -207,7 +207,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('adds session ID handle to state param', async () => {
|
||||
const startResponse = await vmWareCSPAuthenticator.start(
|
||||
const startResponse = await vmwareCloudAuthenticator.start(
|
||||
startRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
@@ -264,7 +264,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
it('stores refresh token in cookie', async () => {
|
||||
const {
|
||||
session: { refreshToken },
|
||||
} = await vmWareCSPAuthenticator.authenticate(
|
||||
} = await vmwareCloudAuthenticator.authenticate(
|
||||
authenticateRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
@@ -273,7 +273,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('responds with ID token', async () => {
|
||||
const { session } = await vmWareCSPAuthenticator.authenticate(
|
||||
const { session } = await vmwareCloudAuthenticator.authenticate(
|
||||
authenticateRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
@@ -282,15 +282,16 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('default transform decodes ID token', async () => {
|
||||
const result = await vmWareCSPAuthenticator.authenticate(
|
||||
const result = await vmwareCloudAuthenticator.authenticate(
|
||||
authenticateRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
|
||||
const { profile } = await vmWareCSPAuthenticator.defaultProfileTransform(
|
||||
result,
|
||||
resolverContext,
|
||||
);
|
||||
const { profile } =
|
||||
await vmwareCloudAuthenticator.defaultProfileTransform(
|
||||
result,
|
||||
resolverContext,
|
||||
);
|
||||
|
||||
expect(profile).toStrictEqual({
|
||||
email: signInInfo.email,
|
||||
@@ -299,7 +300,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('default transform fails if claims are missing', async () => {
|
||||
authenticatorCtx = vmWareCSPAuthenticator.initialize({
|
||||
authenticatorCtx = vmwareCloudAuthenticator.initialize({
|
||||
callbackUrl: 'http://callbackUrl',
|
||||
config: new ConfigReader({
|
||||
clientId: 'placeholderClientId',
|
||||
@@ -307,13 +308,16 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
}),
|
||||
});
|
||||
|
||||
const result = await vmWareCSPAuthenticator.authenticate(
|
||||
const result = await vmwareCloudAuthenticator.authenticate(
|
||||
authenticateRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
|
||||
return expect(
|
||||
vmWareCSPAuthenticator.defaultProfileTransform(result, resolverContext),
|
||||
vmwareCloudAuthenticator.defaultProfileTransform(
|
||||
result,
|
||||
resolverContext,
|
||||
),
|
||||
).rejects.toThrow('ID token organizationId mismatch');
|
||||
});
|
||||
|
||||
@@ -333,13 +337,16 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
),
|
||||
);
|
||||
|
||||
const result = await vmWareCSPAuthenticator.authenticate(
|
||||
const result = await vmwareCloudAuthenticator.authenticate(
|
||||
authenticateRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
|
||||
return expect(
|
||||
vmWareCSPAuthenticator.defaultProfileTransform(result, resolverContext),
|
||||
vmwareCloudAuthenticator.defaultProfileTransform(
|
||||
result,
|
||||
resolverContext,
|
||||
),
|
||||
).rejects.toThrow(
|
||||
'ID token missing required claims: email, given_name, family_name',
|
||||
);
|
||||
@@ -347,7 +354,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
|
||||
it('fails when request has no session', () => {
|
||||
return expect(
|
||||
vmWareCSPAuthenticator.authenticate(
|
||||
vmwareCloudAuthenticator.authenticate(
|
||||
{
|
||||
req: {
|
||||
query: {},
|
||||
@@ -360,7 +367,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
|
||||
it('fails when request has no authorization code', () => {
|
||||
return expect(
|
||||
vmWareCSPAuthenticator.authenticate(
|
||||
vmwareCloudAuthenticator.authenticate(
|
||||
{
|
||||
req: {
|
||||
query: {},
|
||||
@@ -383,7 +390,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('state param is compatible', async () => {
|
||||
const startResponse = await vmWareCSPAuthenticator.start(
|
||||
const startResponse = await vmwareCloudAuthenticator.start(
|
||||
{
|
||||
req: {
|
||||
query: {},
|
||||
@@ -394,7 +401,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
authenticatorCtx,
|
||||
);
|
||||
const { searchParams } = new URL(startResponse.url);
|
||||
const { session } = await vmWareCSPAuthenticator.authenticate(
|
||||
const { session } = await vmwareCloudAuthenticator.authenticate(
|
||||
{
|
||||
req: {
|
||||
query: {
|
||||
@@ -441,7 +448,7 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
it('gets new refresh token', async () => {
|
||||
const {
|
||||
session: { refreshToken },
|
||||
} = await vmWareCSPAuthenticator.refresh(
|
||||
} = await vmwareCloudAuthenticator.refresh(
|
||||
refreshRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
@@ -450,15 +457,16 @@ describe('VMwareCloudServicesAuthenticator', () => {
|
||||
});
|
||||
|
||||
it('default transform decodes ID token', async () => {
|
||||
const result = await vmWareCSPAuthenticator.refresh(
|
||||
const result = await vmwareCloudAuthenticator.refresh(
|
||||
refreshRequest,
|
||||
authenticatorCtx,
|
||||
);
|
||||
|
||||
const { profile } = await vmWareCSPAuthenticator.defaultProfileTransform(
|
||||
result,
|
||||
resolverContext,
|
||||
);
|
||||
const { profile } =
|
||||
await vmwareCloudAuthenticator.defaultProfileTransform(
|
||||
result,
|
||||
resolverContext,
|
||||
);
|
||||
|
||||
expect(profile).toStrictEqual({
|
||||
email: signInInfo.email,
|
||||
+9
-9
@@ -30,22 +30,22 @@ import {
|
||||
Strategy as OAuth2Strategy,
|
||||
} from 'passport-oauth2';
|
||||
|
||||
export interface vmWareCSPAuthenticatorContext {
|
||||
export interface vmwareCloudAuthenticatorContext {
|
||||
organizationId?: string;
|
||||
providerStrategy: OAuth2Strategy;
|
||||
helper: PassportOAuthAuthenticatorHelper;
|
||||
}
|
||||
|
||||
type CSPPassportProfile = PassportProfile & {
|
||||
type vmwarePassportProfile = PassportProfile & {
|
||||
organizationId?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* VMWare CSP Authenticator to be used by `createOAuthProviderFactory`
|
||||
* VMware Cloud Authenticator to be used by `createOAuthProviderFactory`
|
||||
*/
|
||||
export const vmWareCSPAuthenticator = createOAuthAuthenticator<
|
||||
vmWareCSPAuthenticatorContext,
|
||||
CSPPassportProfile
|
||||
export const vmwareCloudAuthenticator = createOAuthAuthenticator<
|
||||
vmwareCloudAuthenticatorContext,
|
||||
vmwarePassportProfile
|
||||
>({
|
||||
defaultProfileTransform: async input => {
|
||||
if (!input.session.idToken) {
|
||||
@@ -120,7 +120,7 @@ export const vmWareCSPAuthenticator = createOAuthAuthenticator<
|
||||
},
|
||||
);
|
||||
|
||||
// Both VMWare & OAuth2Strategy fight over control of the state when PKCE is on, thus this hack
|
||||
// Both VMware & OAuth2Strategy fight over control of the state when PKCE is on, thus this hack
|
||||
const pkceSessionStore = Object.create(
|
||||
(providerStrategy as any)._stateStore,
|
||||
);
|
||||
@@ -197,7 +197,7 @@ export const vmWareCSPAuthenticator = createOAuthAuthenticator<
|
||||
fullProfile: {
|
||||
...result.fullProfile,
|
||||
organizationId: ctx.organizationId,
|
||||
} as CSPPassportProfile,
|
||||
} as vmwarePassportProfile,
|
||||
}));
|
||||
},
|
||||
|
||||
@@ -207,7 +207,7 @@ export const vmWareCSPAuthenticator = createOAuthAuthenticator<
|
||||
fullProfile: {
|
||||
...result.fullProfile,
|
||||
organizationId: ctx.organizationId,
|
||||
} as CSPPassportProfile,
|
||||
} as vmwarePassportProfile,
|
||||
}));
|
||||
},
|
||||
});
|
||||
+4
-4
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* The vmware-csp-provider backend module for the auth plugin.
|
||||
* The vmware-cloud-provider backend module for the auth plugin.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export { vmWareCSPAuthenticator } from './authenticator';
|
||||
export { authModuleVmwareCspProvider as default } from './module';
|
||||
export { vmwareCSPSignInResolvers } from './resolvers';
|
||||
export { vmwareCloudAuthenticator } from './authenticator';
|
||||
export { authModuleVmwareCloudProvider as default } from './module';
|
||||
export { vmwareCloudSignInResolvers } from './resolvers';
|
||||
+4
-5
@@ -37,9 +37,7 @@ import express from 'express';
|
||||
import session from 'express-session';
|
||||
import request from 'supertest';
|
||||
|
||||
import { authModuleVmwareCspProvider } from './module';
|
||||
|
||||
const secret = 'secret';
|
||||
import { authModuleVmwareCloudProvider } from './module';
|
||||
|
||||
function isPromise<T>(value: unknown | Promise<T>): value is Promise<T> {
|
||||
return (
|
||||
@@ -104,6 +102,7 @@ async function createBackendWithSession<TExtensionPoints extends any[]>(
|
||||
const app = express();
|
||||
|
||||
const middleware = MiddlewareFactory.create({ config, logger });
|
||||
const secret = 'secret';
|
||||
|
||||
app.use(
|
||||
session({
|
||||
@@ -174,12 +173,12 @@ async function createBackendWithSession<TExtensionPoints extends any[]>(
|
||||
});
|
||||
}
|
||||
|
||||
describe('authModuleVmwareCspProvider', () => {
|
||||
describe('authModuleVmwareCloudProvider', () => {
|
||||
it('should start', async () => {
|
||||
const backend = await createBackendWithSession({
|
||||
features: [
|
||||
import('@backstage/plugin-auth-backend'),
|
||||
authModuleVmwareCspProvider,
|
||||
authModuleVmwareCloudProvider,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
app: {
|
||||
+6
-6
@@ -20,12 +20,12 @@ import {
|
||||
createOAuthProviderFactory,
|
||||
} from '@backstage/plugin-auth-node';
|
||||
|
||||
import { vmWareCSPAuthenticator } from './authenticator';
|
||||
import { vmwareCSPSignInResolvers } from './resolvers';
|
||||
import { vmwareCloudAuthenticator } from './authenticator';
|
||||
import { vmwareCloudSignInResolvers } from './resolvers';
|
||||
|
||||
export const authModuleVmwareCspProvider = createBackendModule({
|
||||
export const authModuleVmwareCloudProvider = createBackendModule({
|
||||
pluginId: 'auth',
|
||||
moduleId: 'vmware-csp-provider',
|
||||
moduleId: 'vmware-cloud-provider',
|
||||
register(reg) {
|
||||
reg.registerInit({
|
||||
deps: { providers: authProvidersExtensionPoint },
|
||||
@@ -33,9 +33,9 @@ export const authModuleVmwareCspProvider = createBackendModule({
|
||||
providers.registerProvider({
|
||||
providerId: 'vmwareCloudServices',
|
||||
factory: createOAuthProviderFactory({
|
||||
authenticator: vmWareCSPAuthenticator,
|
||||
authenticator: vmwareCloudAuthenticator,
|
||||
signInResolverFactories: {
|
||||
...vmwareCSPSignInResolvers,
|
||||
...vmwareCloudSignInResolvers,
|
||||
...commonSignInResolvers,
|
||||
},
|
||||
}),
|
||||
+8
-8
@@ -22,12 +22,12 @@ import {
|
||||
SignInResolver,
|
||||
} from '@backstage/plugin-auth-node';
|
||||
|
||||
import { vmwareCSPSignInResolvers } from './resolvers';
|
||||
import { vmwareCloudSignInResolvers } from './resolvers';
|
||||
|
||||
describe('CSPResolver', () => {
|
||||
describe('vmwareCloudResolver', () => {
|
||||
let resolverContext: jest.Mocked<AuthResolverContext>;
|
||||
let signInInfo: SignInInfo<OAuthAuthenticatorResult<PassportProfile>>;
|
||||
let cspResolver: SignInResolver<OAuthAuthenticatorResult<PassportProfile>>;
|
||||
let signInResolver: SignInResolver<OAuthAuthenticatorResult<PassportProfile>>;
|
||||
|
||||
beforeEach(() => {
|
||||
resolverContext = {
|
||||
@@ -48,12 +48,12 @@ describe('CSPResolver', () => {
|
||||
},
|
||||
};
|
||||
|
||||
cspResolver =
|
||||
vmwareCSPSignInResolvers.profileEmailMatchingUserEntityEmail();
|
||||
signInResolver =
|
||||
vmwareCloudSignInResolvers.profileEmailMatchingUserEntityEmail();
|
||||
});
|
||||
|
||||
it('looks up backstage identity by email', async () => {
|
||||
const backstageIdentity = await cspResolver(signInInfo, resolverContext);
|
||||
const backstageIdentity = await signInResolver(signInInfo, resolverContext);
|
||||
|
||||
expect(backstageIdentity.token).toBe('backstageToken');
|
||||
expect(resolverContext.signInWithCatalogUser).toHaveBeenCalledWith({
|
||||
@@ -68,7 +68,7 @@ describe('CSPResolver', () => {
|
||||
new NotFoundError('User not found'),
|
||||
);
|
||||
|
||||
const backstageIdentity = await cspResolver(signInInfo, resolverContext);
|
||||
const backstageIdentity = await signInResolver(signInInfo, resolverContext);
|
||||
|
||||
expect(backstageIdentity.token).toBe('defaultBackstageToken');
|
||||
expect(resolverContext.issueToken).toHaveBeenCalledWith({
|
||||
@@ -83,7 +83,7 @@ describe('CSPResolver', () => {
|
||||
const error = new Error('bizarre');
|
||||
resolverContext.signInWithCatalogUser.mockRejectedValue(error);
|
||||
|
||||
return expect(cspResolver(signInInfo, resolverContext)).rejects.toThrow(
|
||||
return expect(signInResolver(signInInfo, resolverContext)).rejects.toThrow(
|
||||
error,
|
||||
);
|
||||
});
|
||||
+2
-2
@@ -23,11 +23,11 @@ import {
|
||||
} from '@backstage/plugin-auth-node';
|
||||
|
||||
/**
|
||||
* Available sign-in resolvers for the VMWare CSP auth provider.
|
||||
* Available sign-in resolvers for the VMware Cloud auth provider.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export namespace vmwareCSPSignInResolvers {
|
||||
export namespace vmwareCloudSignInResolvers {
|
||||
/**
|
||||
* Looks up the user by matching their profile email to the entity's profile email.
|
||||
* If that fails, sign in the user without associating with a catalog user.
|
||||
@@ -1,7 +0,0 @@
|
||||
# Auth Module: VMWare CSP Provider
|
||||
|
||||
This module provides an VMWare CSP auth provider implementation for `@backstage/plugin-auth-backend`.
|
||||
|
||||
## Links
|
||||
|
||||
- [Backstage](https://backstage.io)
|
||||
@@ -4840,9 +4840,9 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@backstage/plugin-auth-backend-module-vmware-csp-provider@workspace:plugins/auth-backend-module-vmware-csp-provider":
|
||||
"@backstage/plugin-auth-backend-module-vmware-cloud-provider@workspace:plugins/auth-backend-module-vmware-cloud-provider":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@backstage/plugin-auth-backend-module-vmware-csp-provider@workspace:plugins/auth-backend-module-vmware-csp-provider"
|
||||
resolution: "@backstage/plugin-auth-backend-module-vmware-cloud-provider@workspace:plugins/auth-backend-module-vmware-cloud-provider"
|
||||
dependencies:
|
||||
"@backstage/backend-app-api": "workspace:^"
|
||||
"@backstage/backend-common": "workspace:^"
|
||||
|
||||
Reference in New Issue
Block a user