1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

refactor: remove PAT experimental flag (#2299)

This commit is contained in:
Nuno Góis 2022-10-31 09:38:30 +00:00 committed by GitHub
parent 3029564304
commit 07821174a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 2 additions and 59 deletions

View File

@ -1,7 +1,6 @@
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { ITab, VerticalTabs } from 'component/common/VerticalTabs/VerticalTabs';
import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { PasswordTab } from './PasswordTab/PasswordTab';
@ -13,8 +12,6 @@ export const Profile = () => {
const location = useLocation();
const navigate = useNavigate();
const { uiConfig } = useUiConfig();
const tabs = [
{ id: 'profile', label: 'Profile' },
{ id: 'password', label: 'Change password', path: 'change-password' },
@ -22,7 +19,6 @@ export const Profile = () => {
id: 'pat',
label: 'Personal API tokens',
path: 'personal-api-tokens',
hidden: !uiConfig.flags.personalAccessTokens,
},
];

View File

@ -41,7 +41,6 @@ export interface IFlags {
ENABLE_DARK_MODE_SUPPORT?: boolean;
embedProxyFrontend?: boolean;
publicSignup?: boolean;
personalAccessTokens?: boolean;
syncSSOGroups?: boolean;
suggestChanges?: boolean;
cloneEnvironment?: boolean;

View File

@ -72,7 +72,6 @@ exports[`should create default config 1`] = `
"cloneEnvironment": false,
"embedProxy": false,
"embedProxyFrontend": false,
"personalAccessTokens": false,
"publicSignup": false,
"responseTimeWithAppName": false,
"suggestChanges": false,
@ -87,7 +86,6 @@ exports[`should create default config 1`] = `
"cloneEnvironment": false,
"embedProxy": false,
"embedProxyFrontend": false,
"personalAccessTokens": false,
"publicSignup": false,
"responseTimeWithAppName": false,
"suggestChanges": false,

View File

@ -1,5 +1,4 @@
import getLogger from '../../test/fixtures/no-logger';
import { createTestConfig } from '../../test/config/test-config';
import patMiddleware from './pat-middleware';
import User from '../types/user';
@ -83,39 +82,6 @@ test('should add user if known token', async () => {
expect(req.user).toBe(apiUser);
});
test('should not add user if disabled', async () => {
const apiUser = new User({
id: 44,
username: 'my-user',
});
const userService = {
getUserByPersonalAccessToken: jest.fn().mockReturnValue(apiUser),
};
const disabledConfig = createTestConfig({
getLogger,
experimental: {
flags: {
personalAccessTokens: false,
},
},
});
const func = patMiddleware(disabledConfig, { userService });
const cb = jest.fn();
const req = {
header: jest.fn().mockReturnValue('user:some-known-token'),
user: undefined,
};
await func(req, undefined, cb);
expect(cb).toHaveBeenCalled();
expect(req.user).toBeFalsy();
});
test('should call next if userService throws exception', async () => {
getLogger.setMuteError(true);
const userService = {

View File

@ -3,19 +3,12 @@ import { IAuthRequest } from '../routes/unleash-types';
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
const patMiddleware = (
{
getLogger,
flagResolver,
}: Pick<IUnleashConfig, 'getLogger' | 'flagResolver'>,
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
{ userService }: any,
): any => {
const logger = getLogger('/middleware/pat-middleware.ts');
logger.debug('Enabling PAT middleware');
if (!flagResolver.isEnabled('personalAccessTokens')) {
return (req, res, next) => next();
}
return async (req: IAuthRequest, res, next) => {
try {
const apiToken = req.header('authorization');

View File

@ -10,10 +10,6 @@ export const defaultExperimentalOptions = {
process.env.UNLEASH_EXPERIMENTAL_EMBED_PROXY,
false,
),
personalAccessTokens: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_PERSONAL_ACCESS_TOKENS,
false,
),
suggestChanges: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_SUGGEST_CHANGES,
false,
@ -54,7 +50,6 @@ export interface IExperimentalOptions {
embedProxyFrontend?: boolean;
batchMetrics?: boolean;
anonymiseEventLog?: boolean;
personalAccessTokens?: boolean;
syncSSOGroups?: boolean;
suggestChanges?: boolean;
cloneEnvironment?: boolean;

View File

@ -38,7 +38,6 @@ process.nextTick(async () => {
batchMetrics: true,
anonymiseEventLog: false,
responseTimeWithAppName: true,
personalAccessTokens: true,
syncSSOGroups: true,
suggestChanges: true,
cloneEnvironment: true,

View File

@ -27,7 +27,6 @@ export function createTestConfig(config?: IUnleashOptions): IUnleashConfig {
embedProxy: true,
embedProxyFrontend: true,
batchMetrics: true,
personalAccessTokens: true,
syncSSOGroups: true,
suggestChanges: true,
cloneEnvironment: true,

View File

@ -16,9 +16,7 @@ tomorrow.setDate(tomorrow.getDate() + 1);
beforeAll(async () => {
db = await dbInit('user_pat', getLogger);
patStore = db.stores.patStore;
app = await setupAppWithAuth(db.stores, {
experimental: { flags: { personalAccessTokens: true } },
});
app = await setupAppWithAuth(db.stores);
await app.request
.post(`/auth/demo/login`)