fix(stage): accept persisted ADMIN human role in maintenance
This commit is contained in:
1 parent
a0d588ba12
commit
69dd6922f6
3 files changed
+15
-1
No files matched your search
@@ -94,6 +94,14 @@ describe('Public authors are attribution only, never principals', () => {
|
||||
const ctx = { getHandler: () => null, getClass: () => null, switchToHttp: () => ({ getRequest: () => ({ user: author }) }) } as any;
|
||||
expect(() => guard.canActivate(ctx)).toThrow(ForbiddenException);
|
||||
});
|
||||
it.each(['Admin', 'ADMIN', 'SUPER_ADMIN'])('human admin guard accepts actual human role %s', role => {
|
||||
const ctx = { switchToHttp: () => ({ getRequest: () => ({ user: { role } }) }) } as any;
|
||||
expect(new HumanAdminGuard().canActivate(ctx)).toBe(true);
|
||||
});
|
||||
it.each(['User_PetOwner', 'adminsuper', '', undefined])('human admin guard denies nonallowlisted role %s', role => {
|
||||
const ctx = { switchToHttp: () => ({ getRequest: () => ({ user: { role } }) }) } as any;
|
||||
expect(() => new HumanAdminGuard().canActivate(ctx)).toThrow(ForbiddenException);
|
||||
});
|
||||
it('human admin guard rejects author with admin role', () => {
|
||||
const ctx = { switchToHttp: () => ({ getRequest: () => ({ user: author }) }) } as any;
|
||||
expect(() => new HumanAdminGuard().canActivate(ctx)).toThrow(ForbiddenException);
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
export class HumanAdminGuard implements CanActivate {
|
||||
canActivate(context: ExecutionContext): boolean {
|
||||
const user = context.switchToHttp().getRequest().user;
|
||||
if (!user || user.isPublicAuthor || user.isApiKey || !['Admin', 'SUPER_ADMIN'].includes(user.role))
|
||||
if (!user || user.isPublicAuthor || user.isApiKey || !['Admin', 'ADMIN', 'SUPER_ADMIN'].includes(user.role))
|
||||
throw new ForbiddenException('Human administrator required');
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -62,6 +62,12 @@ def run(env=os.environ, call=subprocess.run):
|
||||
database_info = json.loads(command(['docker', 'inspect', op.STAGE], capture_output=True).stdout)[0]
|
||||
op.check_identity(database_info)
|
||||
validate_runtime_url(values.get('DATABASE_URL', ''), database_info)
|
||||
# Dedicated maintenance scope uses the independently verified canonical name.
|
||||
# Preserve credentials, remove only the already validated default schema hint.
|
||||
from urllib.parse import urlparse
|
||||
runtime_url = urlparse(values['DATABASE_URL'])
|
||||
credentials = runtime_url.netloc.rsplit('@', 1)[0] + '@' if '@' in runtime_url.netloc else ''
|
||||
values['DATABASE_URL'] = runtime_url._replace(netloc=credentials + op.STAGE + ':5432', query='').geturl()
|
||||
if any('\n' in v or '\r' in v for v in values.values()): raise ValueError('Multiline env refused')
|
||||
live_env = evidence / 'stage.env'
|
||||
op.private_write(live_env, '\n'.join(k + '=' + v for k, v in values.items()).encode())
|
||||
|
||||
Reference in new issue
Block a user