Skip to content

Commit

Permalink
General fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Mar 9, 2022
1 parent 4f45490 commit 08f6c00
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/client/service/vaultsClone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as grpc from '@grpc/grpc-js';
import * as grpcUtils from '../../grpc/utils';
import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb';
import * as validationUtils from '../../validation/utils';
import * as vaultsUtils from '../../vaults/utils';

function vaultsClone({
authenticate,
Expand Down Expand Up @@ -35,8 +36,8 @@ function vaultsClone({
// Vault id
let vaultId;
const vaultNameOrId = vaultMessage.getNameOrId();
vaultId = vaultManager.getVaultId(vaultNameOrId);
vaultId = vaultId ?? validationUtils.parseVaultId(vaultId);
vaultId = vaultsUtils.decodeVaultId(vaultNameOrId);
vaultId = vaultId ?? vaultNameOrId;
// Node id
const nodeId = validationUtils.parseNodeId(nodeMessage.getNodeId());
await vaultManager.cloneVault(nodeId, vaultId);
Expand Down
8 changes: 4 additions & 4 deletions src/client/service/vaultsPermissionGet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Authenticate } from '../types';
import type { VaultManager } from '../../vaults';
import type VaultManager from '../../vaults/VaultManager';
import type { VaultName } from '../../vaults/types';
import type * as grpc from '@grpc/grpc-js';
import type { VaultActions } from '../../vaults/types';
import type ACL from '../../acl/ACL';
import type { NodeId, NodeIdEncoded } from 'nodes/types';
import { IdInternal } from '@matrixai/id';
import { utils as grpcUtils } from '../../grpc';
import * as grpcUtils from '../../grpc/utils';
import * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb';
import * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb';
import * as validationUtils from '../../validation/utils';
Expand Down Expand Up @@ -37,7 +37,7 @@ function vaultsPermissionGet({
// Getting permissions
const rawPermissions = await acl.getVaultPerm(vaultId);
const permissionList: Record<NodeIdEncoded, VaultActions> = {};
// Getting the relevant information.
// Getting the relevant information
for (const nodeId in rawPermissions) {
permissionList[nodeId] = rawPermissions[nodeId].vaults[vaultId];
}
Expand All @@ -46,7 +46,7 @@ function vaultsPermissionGet({
vaultPermissionsMessage.setVault(vaultMessage);
const nodeMessage = new nodesPB.Node();

// Constructing the message.
// Constructing the message
for (const nodeIdString in permissionList) {
const nodeId = IdInternal.fromString<NodeId>(nodeIdString);
nodeMessage.setNodeId(nodesUtils.encodeNodeId(nodeId));
Expand Down
4 changes: 2 additions & 2 deletions src/client/service/vaultsPermissionSet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Authenticate } from '../types';
import type { VaultName } from '../../vaults/types';
import type { VaultManager } from '../../vaults';
import type VaultManager from '../../vaults/VaultManager';
import type GestaltGraph from '../../gestalts/GestaltGraph';
import type ACL from '../../acl/ACL';
import type NotificationsManager from '../../notifications/NotificationsManager';
Expand All @@ -10,7 +10,7 @@ import * as grpc from '@grpc/grpc-js';
import * as vaultsUtils from '../../vaults/utils';
import * as vaultsErrors from '../../vaults/errors';
import * as validationUtils from '../../validation/utils';
import { utils as grpcUtils } from '../../grpc';
import * as grpcUtils from '../../grpc/utils';
import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb';

function vaultsPermissionSet({
Expand Down
6 changes: 3 additions & 3 deletions src/client/service/vaultsPermissionUnset.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Authenticate } from '../types';
import type { VaultName } from '../../vaults/types';
import type { VaultManager } from '../../vaults';
import type VaultManager from '../../vaults/VaultManager';
import type GestaltGraph from '../../gestalts/GestaltGraph';
import type ACL from '../../acl/ACL';
import type * as vaultsPB from '../../proto/js/polykey/v1/vaults/vaults_pb';
import * as grpc from '@grpc/grpc-js';
import * as vaultsErrors from '../../vaults/errors';
import * as validationUtils from '../../validation/utils';
import { utils as grpcUtils } from '../../grpc';
import * as grpcUtils from '../../grpc/utils';
import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb';

function vaultsPermissionUnset({
Expand Down Expand Up @@ -54,7 +54,7 @@ function vaultsPermissionUnset({
for (const action of actions) {
await acl.unsetVaultAction(vaultId, nodeId, action);
}
// We need to check if there are still shared vaults.
// We need to check if there are still shared vaults
const nodePermissions = await acl.getNodePerm(nodeId);
// Remove scan permissions if no more shared vaults
if (nodePermissions != null) {
Expand Down
4 changes: 1 addition & 3 deletions src/vaults/VaultManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,7 @@ class VaultManager {
/**
* Returns all the shared vaults for a NodeId.
*/
public async *handleScanVaults(
nodeId: NodeId,
): AsyncGenerator<{
public async *handleScanVaults(nodeId: NodeId): AsyncGenerator<{
vaultId: VaultId;
vaultName: VaultName;
vaultPermissions: VaultAction[];
Expand Down
8 changes: 4 additions & 4 deletions tests/vaults/VaultManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ describe('VaultManager', () => {
await vaultManager?.destroy();
}
});
describe.skip('With remote agents', () => {
describe('With remote agents', () => {
let allDataDir: string;
let keyManager: KeyManager;
let fwdProxy: ForwardProxy;
Expand Down Expand Up @@ -1388,7 +1388,7 @@ describe('VaultManager', () => {
// No permissions for vault3

// scanning vaults
const gen = vaultManager.handleScanVaults(nodeId1, acl);
const gen = vaultManager.handleScanVaults(nodeId1);
const vaults: Record<VaultId, [VaultName, VaultAction[]]> = {};
for await (const vault of gen) {
vaults[vault.vaultId] = [vault.vaultName, vault.vaultPermissions];
Expand All @@ -1399,14 +1399,14 @@ describe('VaultManager', () => {

// Should throw due to no permission
await expect(async () => {
for await (const _ of vaultManager.handleScanVaults(nodeId2, acl)) {
for await (const _ of vaultManager.handleScanVaults(nodeId2)) {
// Should throw
}
}).rejects.toThrow(vaultsErrors.ErrorVaultsPermissionDenied);
// Should throw due to lack of scan permission
await gestaltGraph.setGestaltActionByNode(nodeId2, 'notify');
await expect(async () => {
for await (const _ of vaultManager.handleScanVaults(nodeId2, acl)) {
for await (const _ of vaultManager.handleScanVaults(nodeId2)) {
// Should throw
}
}).rejects.toThrow(vaultsErrors.ErrorVaultsPermissionDenied);
Expand Down

0 comments on commit 08f6c00

Please sign in to comment.