mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-09 01:17:06 +02:00
refactor: remove PAT experimental flag (#2299)
This commit is contained in:
parent
3029564304
commit
07821174a5
@ -1,7 +1,6 @@
|
|||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { ITab, VerticalTabs } from 'component/common/VerticalTabs/VerticalTabs';
|
import { ITab, VerticalTabs } from 'component/common/VerticalTabs/VerticalTabs';
|
||||||
import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
||||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useLocation, useNavigate } from 'react-router-dom';
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
import { PasswordTab } from './PasswordTab/PasswordTab';
|
import { PasswordTab } from './PasswordTab/PasswordTab';
|
||||||
@ -13,8 +12,6 @@ export const Profile = () => {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { uiConfig } = useUiConfig();
|
|
||||||
|
|
||||||
const tabs = [
|
const tabs = [
|
||||||
{ id: 'profile', label: 'Profile' },
|
{ id: 'profile', label: 'Profile' },
|
||||||
{ id: 'password', label: 'Change password', path: 'change-password' },
|
{ id: 'password', label: 'Change password', path: 'change-password' },
|
||||||
@ -22,7 +19,6 @@ export const Profile = () => {
|
|||||||
id: 'pat',
|
id: 'pat',
|
||||||
label: 'Personal API tokens',
|
label: 'Personal API tokens',
|
||||||
path: 'personal-api-tokens',
|
path: 'personal-api-tokens',
|
||||||
hidden: !uiConfig.flags.personalAccessTokens,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ export interface IFlags {
|
|||||||
ENABLE_DARK_MODE_SUPPORT?: boolean;
|
ENABLE_DARK_MODE_SUPPORT?: boolean;
|
||||||
embedProxyFrontend?: boolean;
|
embedProxyFrontend?: boolean;
|
||||||
publicSignup?: boolean;
|
publicSignup?: boolean;
|
||||||
personalAccessTokens?: boolean;
|
|
||||||
syncSSOGroups?: boolean;
|
syncSSOGroups?: boolean;
|
||||||
suggestChanges?: boolean;
|
suggestChanges?: boolean;
|
||||||
cloneEnvironment?: boolean;
|
cloneEnvironment?: boolean;
|
||||||
|
@ -72,7 +72,6 @@ exports[`should create default config 1`] = `
|
|||||||
"cloneEnvironment": false,
|
"cloneEnvironment": false,
|
||||||
"embedProxy": false,
|
"embedProxy": false,
|
||||||
"embedProxyFrontend": false,
|
"embedProxyFrontend": false,
|
||||||
"personalAccessTokens": false,
|
|
||||||
"publicSignup": false,
|
"publicSignup": false,
|
||||||
"responseTimeWithAppName": false,
|
"responseTimeWithAppName": false,
|
||||||
"suggestChanges": false,
|
"suggestChanges": false,
|
||||||
@ -87,7 +86,6 @@ exports[`should create default config 1`] = `
|
|||||||
"cloneEnvironment": false,
|
"cloneEnvironment": false,
|
||||||
"embedProxy": false,
|
"embedProxy": false,
|
||||||
"embedProxyFrontend": false,
|
"embedProxyFrontend": false,
|
||||||
"personalAccessTokens": false,
|
|
||||||
"publicSignup": false,
|
"publicSignup": false,
|
||||||
"responseTimeWithAppName": false,
|
"responseTimeWithAppName": false,
|
||||||
"suggestChanges": false,
|
"suggestChanges": false,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import getLogger from '../../test/fixtures/no-logger';
|
import getLogger from '../../test/fixtures/no-logger';
|
||||||
import { createTestConfig } from '../../test/config/test-config';
|
|
||||||
import patMiddleware from './pat-middleware';
|
import patMiddleware from './pat-middleware';
|
||||||
import User from '../types/user';
|
import User from '../types/user';
|
||||||
|
|
||||||
@ -83,39 +82,6 @@ test('should add user if known token', async () => {
|
|||||||
expect(req.user).toBe(apiUser);
|
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 () => {
|
test('should call next if userService throws exception', async () => {
|
||||||
getLogger.setMuteError(true);
|
getLogger.setMuteError(true);
|
||||||
const userService = {
|
const userService = {
|
||||||
|
@ -3,19 +3,12 @@ import { IAuthRequest } from '../routes/unleash-types';
|
|||||||
|
|
||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||||
const patMiddleware = (
|
const patMiddleware = (
|
||||||
{
|
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
|
||||||
getLogger,
|
|
||||||
flagResolver,
|
|
||||||
}: Pick<IUnleashConfig, 'getLogger' | 'flagResolver'>,
|
|
||||||
{ userService }: any,
|
{ userService }: any,
|
||||||
): any => {
|
): any => {
|
||||||
const logger = getLogger('/middleware/pat-middleware.ts');
|
const logger = getLogger('/middleware/pat-middleware.ts');
|
||||||
logger.debug('Enabling PAT middleware');
|
logger.debug('Enabling PAT middleware');
|
||||||
|
|
||||||
if (!flagResolver.isEnabled('personalAccessTokens')) {
|
|
||||||
return (req, res, next) => next();
|
|
||||||
}
|
|
||||||
|
|
||||||
return async (req: IAuthRequest, res, next) => {
|
return async (req: IAuthRequest, res, next) => {
|
||||||
try {
|
try {
|
||||||
const apiToken = req.header('authorization');
|
const apiToken = req.header('authorization');
|
||||||
|
@ -10,10 +10,6 @@ export const defaultExperimentalOptions = {
|
|||||||
process.env.UNLEASH_EXPERIMENTAL_EMBED_PROXY,
|
process.env.UNLEASH_EXPERIMENTAL_EMBED_PROXY,
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
personalAccessTokens: parseEnvVarBoolean(
|
|
||||||
process.env.UNLEASH_EXPERIMENTAL_PERSONAL_ACCESS_TOKENS,
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
suggestChanges: parseEnvVarBoolean(
|
suggestChanges: parseEnvVarBoolean(
|
||||||
process.env.UNLEASH_EXPERIMENTAL_SUGGEST_CHANGES,
|
process.env.UNLEASH_EXPERIMENTAL_SUGGEST_CHANGES,
|
||||||
false,
|
false,
|
||||||
@ -54,7 +50,6 @@ export interface IExperimentalOptions {
|
|||||||
embedProxyFrontend?: boolean;
|
embedProxyFrontend?: boolean;
|
||||||
batchMetrics?: boolean;
|
batchMetrics?: boolean;
|
||||||
anonymiseEventLog?: boolean;
|
anonymiseEventLog?: boolean;
|
||||||
personalAccessTokens?: boolean;
|
|
||||||
syncSSOGroups?: boolean;
|
syncSSOGroups?: boolean;
|
||||||
suggestChanges?: boolean;
|
suggestChanges?: boolean;
|
||||||
cloneEnvironment?: boolean;
|
cloneEnvironment?: boolean;
|
||||||
|
@ -38,7 +38,6 @@ process.nextTick(async () => {
|
|||||||
batchMetrics: true,
|
batchMetrics: true,
|
||||||
anonymiseEventLog: false,
|
anonymiseEventLog: false,
|
||||||
responseTimeWithAppName: true,
|
responseTimeWithAppName: true,
|
||||||
personalAccessTokens: true,
|
|
||||||
syncSSOGroups: true,
|
syncSSOGroups: true,
|
||||||
suggestChanges: true,
|
suggestChanges: true,
|
||||||
cloneEnvironment: true,
|
cloneEnvironment: true,
|
||||||
|
@ -27,7 +27,6 @@ export function createTestConfig(config?: IUnleashOptions): IUnleashConfig {
|
|||||||
embedProxy: true,
|
embedProxy: true,
|
||||||
embedProxyFrontend: true,
|
embedProxyFrontend: true,
|
||||||
batchMetrics: true,
|
batchMetrics: true,
|
||||||
personalAccessTokens: true,
|
|
||||||
syncSSOGroups: true,
|
syncSSOGroups: true,
|
||||||
suggestChanges: true,
|
suggestChanges: true,
|
||||||
cloneEnvironment: true,
|
cloneEnvironment: true,
|
||||||
|
@ -16,9 +16,7 @@ tomorrow.setDate(tomorrow.getDate() + 1);
|
|||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
db = await dbInit('user_pat', getLogger);
|
db = await dbInit('user_pat', getLogger);
|
||||||
patStore = db.stores.patStore;
|
patStore = db.stores.patStore;
|
||||||
app = await setupAppWithAuth(db.stores, {
|
app = await setupAppWithAuth(db.stores);
|
||||||
experimental: { flags: { personalAccessTokens: true } },
|
|
||||||
});
|
|
||||||
|
|
||||||
await app.request
|
await app.request
|
||||||
.post(`/auth/demo/login`)
|
.post(`/auth/demo/login`)
|
||||||
|
Loading…
Reference in New Issue
Block a user