mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	chore: remove feature toggle kill switch for admin token UI (#9154)
## About the changes This was released with 6.6 and now this flag is no longer needed
This commit is contained in:
		
							parent
							
								
									b39adc1d54
								
							
						
					
					
						commit
						fb95415d27
					
				@ -6,17 +6,12 @@ import getApp from '../../app';
 | 
				
			|||||||
import supertest from 'supertest';
 | 
					import supertest from 'supertest';
 | 
				
			||||||
import { addDays } from 'date-fns';
 | 
					import { addDays } from 'date-fns';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getSetup(adminTokenKillSwitchEnabled: boolean) {
 | 
					async function getSetup() {
 | 
				
			||||||
    const base = `/random${Math.round(Math.random() * 1000)}`;
 | 
					    const base = `/random${Math.round(Math.random() * 1000)}`;
 | 
				
			||||||
    const perms = permissions();
 | 
					    const perms = permissions();
 | 
				
			||||||
    const config = createTestConfig({
 | 
					    const config = createTestConfig({
 | 
				
			||||||
        preHook: perms.hook,
 | 
					        preHook: perms.hook,
 | 
				
			||||||
        server: { baseUriPath: base },
 | 
					        server: { baseUriPath: base },
 | 
				
			||||||
        experimental: {
 | 
					 | 
				
			||||||
            flags: {
 | 
					 | 
				
			||||||
                adminTokenKillSwitch: adminTokenKillSwitchEnabled,
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        //@ts-ignore - Just testing, so only need the isEnabled call here
 | 
					        //@ts-ignore - Just testing, so only need the isEnabled call here
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    const stores = createStores();
 | 
					    const stores = createStores();
 | 
				
			||||||
@ -41,23 +36,8 @@ async function getSetup(adminTokenKillSwitchEnabled: boolean) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('Admin token killswitch', () => {
 | 
					describe('Admin token killswitch', () => {
 | 
				
			||||||
    test('If killswitch is off we can still create admin tokens', async () => {
 | 
					 | 
				
			||||||
        const setup = await getSetup(false);
 | 
					 | 
				
			||||||
        return setup.request
 | 
					 | 
				
			||||||
            .post(`${setup.base}/api/admin/api-tokens`)
 | 
					 | 
				
			||||||
            .set('Content-Type', 'application/json')
 | 
					 | 
				
			||||||
            .send({
 | 
					 | 
				
			||||||
                expiresAt: addDays(new Date(), 60),
 | 
					 | 
				
			||||||
                type: 'ADMIN',
 | 
					 | 
				
			||||||
                tokenName: 'Non killswitched',
 | 
					 | 
				
			||||||
            })
 | 
					 | 
				
			||||||
            .expect(201)
 | 
					 | 
				
			||||||
            .expect((res) => {
 | 
					 | 
				
			||||||
                expect(res.body.secret).toBeTruthy();
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    test('If killswitch is on we will get an operation denied if we try to create an admin token', async () => {
 | 
					    test('If killswitch is on we will get an operation denied if we try to create an admin token', async () => {
 | 
				
			||||||
        const setup = await getSetup(true);
 | 
					        const setup = await getSetup();
 | 
				
			||||||
        return setup.request
 | 
					        return setup.request
 | 
				
			||||||
            .post(`${setup.base}/api/admin/api-tokens`)
 | 
					            .post(`${setup.base}/api/admin/api-tokens`)
 | 
				
			||||||
            .set('Content-Type', 'application/json')
 | 
					            .set('Content-Type', 'application/json')
 | 
				
			||||||
@ -74,7 +54,7 @@ describe('Admin token killswitch', () => {
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    test('If killswitch is on we can still create a client token', async () => {
 | 
					    test('If killswitch is on we can still create a client token', async () => {
 | 
				
			||||||
        const setup = await getSetup(true);
 | 
					        const setup = await getSetup();
 | 
				
			||||||
        return setup.request
 | 
					        return setup.request
 | 
				
			||||||
            .post(`${setup.base}/api/admin/api-tokens`)
 | 
					            .post(`${setup.base}/api/admin/api-tokens`)
 | 
				
			||||||
            .set('Content-Type', 'application/json')
 | 
					            .set('Content-Type', 'application/json')
 | 
				
			||||||
@ -91,7 +71,7 @@ describe('Admin token killswitch', () => {
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    test('If killswitch is on we can still create a frontend token', async () => {
 | 
					    test('If killswitch is on we can still create a frontend token', async () => {
 | 
				
			||||||
        const setup = await getSetup(true);
 | 
					        const setup = await getSetup();
 | 
				
			||||||
        return setup.request
 | 
					        return setup.request
 | 
				
			||||||
            .post(`${setup.base}/api/admin/api-tokens`)
 | 
					            .post(`${setup.base}/api/admin/api-tokens`)
 | 
				
			||||||
            .set('Content-Type', 'application/json')
 | 
					            .set('Content-Type', 'application/json')
 | 
				
			||||||
 | 
				
			|||||||
@ -306,10 +306,7 @@ export class ApiTokenController extends Controller {
 | 
				
			|||||||
        const permissionRequired = tokenTypeToCreatePermission(
 | 
					        const permissionRequired = tokenTypeToCreatePermission(
 | 
				
			||||||
            createToken.type,
 | 
					            createToken.type,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        if (
 | 
					        if (createToken.type.toUpperCase() === 'ADMIN') {
 | 
				
			||||||
            createToken.type.toUpperCase() === 'ADMIN' &&
 | 
					 | 
				
			||||||
            this.flagResolver.isEnabled('adminTokenKillSwitch')
 | 
					 | 
				
			||||||
        ) {
 | 
					 | 
				
			||||||
            throw new OperationDeniedError(
 | 
					            throw new OperationDeniedError(
 | 
				
			||||||
                `Admin tokens are disabled in this instance. Use a Service account or a PAT to access admin operations instead`,
 | 
					                `Admin tokens are disabled in this instance. Use a Service account or a PAT to access admin operations instead`,
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,6 @@ export type IFlagKey =
 | 
				
			|||||||
    | 'celebrateUnleash'
 | 
					    | 'celebrateUnleash'
 | 
				
			||||||
    | 'feedbackPosting'
 | 
					    | 'feedbackPosting'
 | 
				
			||||||
    | 'extendedUsageMetrics'
 | 
					    | 'extendedUsageMetrics'
 | 
				
			||||||
    | 'adminTokenKillSwitch'
 | 
					 | 
				
			||||||
    | 'feedbackComments'
 | 
					    | 'feedbackComments'
 | 
				
			||||||
    | 'showInactiveUsers'
 | 
					    | 'showInactiveUsers'
 | 
				
			||||||
    | 'killScheduledChangeRequestCache'
 | 
					    | 'killScheduledChangeRequestCache'
 | 
				
			||||||
@ -158,10 +157,6 @@ const flags: IFlags = {
 | 
				
			|||||||
        process.env.UNLEASH_EXPERIMENTAL_EXTENDED_USAGE_METRICS,
 | 
					        process.env.UNLEASH_EXPERIMENTAL_EXTENDED_USAGE_METRICS,
 | 
				
			||||||
        false,
 | 
					        false,
 | 
				
			||||||
    ),
 | 
					    ),
 | 
				
			||||||
    adminTokenKillSwitch: parseEnvVarBoolean(
 | 
					 | 
				
			||||||
        process.env.UNLEASH_EXPERIMENTAL_ADMIN_TOKEN_KILL_SWITCH,
 | 
					 | 
				
			||||||
        true,
 | 
					 | 
				
			||||||
    ),
 | 
					 | 
				
			||||||
    outdatedSdksBanner: parseEnvVarBoolean(
 | 
					    outdatedSdksBanner: parseEnvVarBoolean(
 | 
				
			||||||
        process.env.UNLEASH_EXPERIMENTAL_OUTDATED_SDKS_BANNER,
 | 
					        process.env.UNLEASH_EXPERIMENTAL_OUTDATED_SDKS_BANNER,
 | 
				
			||||||
        false,
 | 
					        false,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user