mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
parent
100bffbc6a
commit
d5d6c5ed08
6 changed files with 1 additions and 59 deletions
|
@ -1,34 +0,0 @@
|
|||
import { UserRole } from '@logto/schemas';
|
||||
import { Context } from 'koa';
|
||||
|
||||
import { mockUser } from '@/__mocks__';
|
||||
import RequestError from '@/errors/RequestError';
|
||||
import { createContextWithRouteParameters } from '@/utils/test-utils';
|
||||
|
||||
import { WithAuthContext } from './koa-auth';
|
||||
import koaRoleGuard from './koa-role-guard';
|
||||
import { WithUserInfoContext } from './koa-user-info';
|
||||
|
||||
describe('koaRoleGuard middleware', () => {
|
||||
const baseCtx = createContextWithRouteParameters();
|
||||
|
||||
const ctx: WithUserInfoContext<Context & WithAuthContext> = {
|
||||
...baseCtx,
|
||||
auth: 'foo',
|
||||
userInfo: mockUser,
|
||||
};
|
||||
|
||||
const unauthorizedError = new RequestError({ code: 'auth.unauthorized', status: 401 });
|
||||
|
||||
const next = jest.fn();
|
||||
|
||||
it('should throw if user dose not have admin role', async () => {
|
||||
ctx.userInfo.roleNames = ['guest'];
|
||||
await expect(koaRoleGuard(UserRole.Admin)(ctx, next)).rejects.toMatchError(unauthorizedError);
|
||||
});
|
||||
|
||||
it('should not throw for admin user', async () => {
|
||||
ctx.userInfo.roleNames = ['admin'];
|
||||
await expect(koaRoleGuard(UserRole.Admin)(ctx, next)).resolves.not.toThrow();
|
||||
});
|
||||
});
|
|
@ -1,20 +0,0 @@
|
|||
import { MiddlewareType } from 'koa';
|
||||
|
||||
import RequestError from '@/errors/RequestError';
|
||||
import assertThat from '@/utils/assert-that';
|
||||
|
||||
import { WithUserInfoContext } from './koa-user-info';
|
||||
|
||||
export default function koaRoleGuard<StateT, ContextT extends WithUserInfoContext, ResponseBodyT>(
|
||||
// TODO: need to figure out how to infer enum role types from db value
|
||||
role: string
|
||||
): MiddlewareType<StateT, ContextT, ResponseBodyT> {
|
||||
return async ({ userInfo }, next) => {
|
||||
assertThat(
|
||||
userInfo.roleNames?.includes(role),
|
||||
new RequestError({ code: 'auth.unauthorized', status: 401 })
|
||||
);
|
||||
|
||||
return next();
|
||||
};
|
||||
}
|
|
@ -47,7 +47,6 @@ export const deletePasscodesByIds = async (ids: string[]) => {
|
|||
`);
|
||||
|
||||
if (rowCount !== ids.length) {
|
||||
// TODO: need to track the failed ids
|
||||
throw new DeletionError(Passcodes.table, `${ids.join(',')}`);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -27,8 +27,6 @@ export default function resourceRoutes<T extends AuthedRouter>(router: T) {
|
|||
]);
|
||||
|
||||
ctx.pagination.totalCount = count;
|
||||
|
||||
// TODO: query scopes of all resources and insert into the response data
|
||||
ctx.body = resources;
|
||||
|
||||
return next();
|
||||
|
|
|
@ -7,7 +7,7 @@ export type Props = {
|
|||
htmlType?: 'button' | 'submit' | 'reset';
|
||||
isDisabled?: boolean;
|
||||
className?: string;
|
||||
children: ReactNode; // TODO: make it i18nKey with optional params
|
||||
children: ReactNode;
|
||||
type?: 'primary' | 'secondary' | 'outline';
|
||||
size?: 'small' | 'large';
|
||||
onClick?: React.MouseEventHandler;
|
||||
|
|
|
@ -69,7 +69,6 @@ export const defaultCountryCode: CountryCode = 'CN';
|
|||
export const defaultCountryCallingCode = getCountryCallingCode(defaultCountryCode);
|
||||
|
||||
const usePhoneNumber = () => {
|
||||
// TODO: Get Default Country Code
|
||||
const [phoneNumber, setPhoneNumber] = useState<PhoneNumberData>({
|
||||
countryCallingCode: defaultCountryCallingCode,
|
||||
nationalNumber: '',
|
||||
|
|
Loading…
Add table
Reference in a new issue