Skip to content

Commit

Permalink
test protocol query/configure permissions, scopes to protocol for pro…
Browse files Browse the repository at this point in the history
…tocol interface messages
  • Loading branch information
LiranCohen committed Sep 11, 2024
1 parent 282dbba commit 5ff37b6
Show file tree
Hide file tree
Showing 2 changed files with 580 additions and 458 deletions.
18 changes: 4 additions & 14 deletions packages/agent/src/permissions-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export class AgentPermissionsApi implements PermissionsApi {
if (scopeMessageType === messageType) {
if (isRecordsType(messageType)) {
const recordScope = scope as DwnRecordsPermissionScope;
if (!this.matchesProtocol(recordScope, protocol)) {
if (recordScope.protocol !== protocol) {
return false;
}

Expand All @@ -386,11 +386,12 @@ export class AgentPermissionsApi implements PermissionsApi {
}
} else {
const messagesScope = scope as DwnMessagesPermissionScope | DwnProtocolPermissionScope;
if (this.protocolScopeUnrestricted(messagesScope)) {
// Checks for unrestricted protocol scope, if no protocol is defined in the scope it is unrestricted
if (messagesScope.protocol === undefined) {
return true;
}

if (!this.matchesProtocol(messagesScope, protocol)) {
if (messagesScope.protocol !== protocol) {
return false;
}

Expand All @@ -401,17 +402,6 @@ export class AgentPermissionsApi implements PermissionsApi {
return false;
}

private static matchesProtocol(scope: DwnPermissionScope & { protocol?: string }, protocol?: string): boolean {
return scope.protocol !== undefined && scope.protocol === protocol;
}

/**
* Checks if the scope is restricted to a specific protocol
*/
private static protocolScopeUnrestricted(scope: DwnPermissionScope & { protocol?: string }): boolean {
return scope.protocol === undefined;
}

private static isUnrestrictedProtocolScope(scope: DwnPermissionScope & { contextId?: string, protocolPath?: string }): boolean {
return scope.contextId === undefined && scope.protocolPath === undefined;
}
Expand Down
Loading

0 comments on commit 5ff37b6

Please sign in to comment.