New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

oso-cloud

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oso-cloud - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0-alpha.1

40

dist/api.d.ts
export declare type Foo = {
hello: string;
api_version: number;
};

@@ -84,2 +85,16 @@ export declare type ApiResult = {

};
export declare type QueryResult = {
results: VariableFact[];
};
export declare type VariableFact = {
predicate: string;
args: Variable[];
};
export declare type TypedVar = {
type: string;
};
export declare type Query = {
fact: VariableFact;
context_facts: Fact[];
};
export declare type StatsResult = {

@@ -91,6 +106,15 @@ num_roles: number;

};
export declare type Backup = {
key: string;
name: string;
filepath: string;
export declare const enum VariableKind {
TypedId = "TypedId",
TypedVariable = "TypedVariable",
FreeVariable = "FreeVariable"
}
export declare type Variable = {
kind: VariableKind.TypedVariable;
value: TypedVar;
} | {
kind: VariableKind.FreeVariable;
} | {
kind: VariableKind.TypedId;
value: TypedId;
};

@@ -108,2 +132,3 @@ export declare class Api {

"User-Agent": string;
"X-OsoApiVersion": string;
};

@@ -113,3 +138,3 @@ hello(): Promise<Foo>;

postPolicy(data: Policy): Promise<ApiResult>;
getFacts(predicate: string, args: TypedId[]): Promise<Fact[]>;
getFacts(predicate: string, args: Variable[]): Promise<Fact[]>;
postFacts(data: Fact): Promise<Fact>;

@@ -130,6 +155,7 @@ deleteFacts(data: Fact): Promise<ApiResult>;

postActions(data: ActionsQuery): Promise<ActionsResult>;
postQuery(data: Query): Promise<QueryResult>;
getStats(): Promise<StatsResult>;
clearData(): Promise<ApiResult>;
listBackups(): Promise<Backup[]>;
createBackup(): Promise<Backup>;
listBackups(): Promise<ApiResult[]>;
createBackup(): Promise<ApiResult>;
deleteBackup(backup_key: string): Promise<ApiResult>;

@@ -136,0 +162,0 @@ restoreFromBackup(backup_key: string): Promise<ApiResult>;

19

dist/api.js

@@ -49,2 +49,3 @@ "use strict";

"User-Agent": "Oso Cloud (nodejs)",
"X-OsoApiVersion": "0",
};

@@ -73,7 +74,10 @@ }

let params = {};
args.forEach(({ type, id }, i) => {
if (type !== "")
params[`args.${i}.type`] = type;
if (id !== "")
params[`args.${i}.id`] = id;
args.forEach((variable, i) => {
if (variable.kind == "TypedVariable" /* VariableKind.TypedVariable */) {
params[`args.${i}.type`] = variable.value.type;
}
else if (variable.kind == "TypedId" /* VariableKind.TypedId */) {
params[`args.${i}.type`] = variable.value.type;
params[`args.${i}.id`] = variable.value.id;
}
});

@@ -173,2 +177,7 @@ params["predicate"] = predicate;

}
postQuery(data) {
const params = {};
const result = this._post(`/query`, params, data);
return result;
}
getStats() {

@@ -175,0 +184,0 @@ const params = {};

import { Instance } from ".";
import { Fact } from "./api";
import { Fact, Variable, TypedId } from "./api";
export declare function mapParamsToFacts(params?: [predicate: string, ...args: Instance[]][]): Fact[];
export declare function mapFactsToParams(facts?: Fact[]): [predicate: string, ...args: Instance[]][];
export declare function getTypeAndId(instance: Instance): {
type: string;
id: string;
};
export declare function toTypedId(instance: Instance): TypedId;
export declare function fromTypedId(typedId: TypedId): Instance;
export declare function toVariable(instance: Instance): Variable;
export declare function fromVariable(variable: Variable): Instance;
//# sourceMappingURL=helpers.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTypeAndId = exports.mapFactsToParams = exports.mapParamsToFacts = void 0;
exports.fromVariable = exports.toVariable = exports.fromTypedId = exports.toTypedId = exports.mapFactsToParams = exports.mapParamsToFacts = void 0;
function paramToFact(predicate, ...args) {
return { predicate, args: args.map(getTypeAndId) };
return { predicate, args: args.map(toTypedId) };
}

@@ -14,3 +14,3 @@ function mapParamsToFacts(params) {

function factToParam(fact) {
return [fact.predicate, ...fact.args];
return [fact.predicate, ...fact.args.map(fromTypedId)];
}

@@ -23,26 +23,77 @@ function mapFactsToParams(facts) {

exports.mapFactsToParams = mapFactsToParams;
function getTypeAndId(instance) {
function toTypedId(instance) {
if (instance === null) {
throw new TypeError(`Oso: No type and id present on instance passed to Oso: ${instance}\n\nAll objects passed to Oso must either be strings or have a type and id property, like:\n\t{ type: "User", id: "alice" }`);
}
if (typeof instance === "string") {
if (instance === "") {
throw new TypeError(`Instance can not be an empty string`);
}
return { type: "String", id: instance };
}
else if ("getId" in instance && "getType" in instance) {
return { type: instance.getType(), id: instance.getId() };
if (instance.type === undefined ||
instance.id === undefined ||
instance.type === null ||
instance.id === null) {
throw new TypeError(`Oso: No type and id present on instance passed to Oso: ${instance}\n\nAll objects passed to Oso must either be strings or have a type and id property, like:\n\t{ type: "User", id: "alice" }`);
}
else if ("id" in instance) {
let id = instance.id;
let type;
if (instance.type) {
type = instance.type;
return { type: instance.type, id: instance.id };
}
exports.toTypedId = toTypedId;
function fromTypedId(typedId) {
if (typedId.type == "String") {
return typedId.id;
}
return { id: typedId.id, type: typedId.type };
}
exports.fromTypedId = fromTypedId;
function toVariable(instance) {
if (instance === null) {
return { kind: "FreeVariable" /* VariableKind.FreeVariable */ };
}
if (typeof instance === "string") {
if (instance === "") {
throw new TypeError(`Oso: Instance cannot be an empty string. For wildcards, use the empty object ({}) or null.`);
}
return {
kind: "TypedId" /* VariableKind.TypedId */,
value: { type: "String", id: instance },
};
}
if (instance.id === undefined || instance.id === null) {
if (instance.type === undefined || instance.type === null) {
return { kind: "FreeVariable" /* VariableKind.FreeVariable */ };
}
else {
type = instance.constructor.name;
console.warn(`Oso: WARNING: implicitly using a class name to determine the type of instance with type = '${type}' and id = '${id}'. This pattern is deprecated. Please pass an object with 'type' and 'id' properties, or implement 'getId()' and 'getType()' methods on your class.`);
return {
kind: "TypedVariable" /* VariableKind.TypedVariable */,
value: { type: instance.type },
};
}
return { type, id };
}
else {
throw new TypeError(`Oso: unable to determine type and ID for instance: ${instance}. \n\nPass either a string, or an object with fields 'type' and 'id' fields.`);
if (instance.type === undefined || instance.type === null) {
throw new TypeError(`Oso: Instances with an ID must also have a type: ${instance}`);
}
return {
kind: "TypedId" /* VariableKind.TypedId */,
value: { type: instance.type, id: instance.id },
};
}
}
exports.getTypeAndId = getTypeAndId;
exports.toVariable = toVariable;
function fromVariable(variable) {
switch (variable.kind) {
case "FreeVariable" /* VariableKind.FreeVariable */:
return null;
case "TypedVariable" /* VariableKind.TypedVariable */:
return { type: variable.value.type };
case "TypedId" /* VariableKind.TypedId */:
if (variable.value.type == "String") {
return variable.value.id;
}
return { type: variable.value.type, id: variable.value.id };
}
}
exports.fromVariable = fromVariable;
//# sourceMappingURL=helpers.js.map
import { Api } from "./api";
export declare type OsoInstance = {
getType(): string;
getId(): string;
};
export declare type Instance = string | {
id: string;
export declare type Instance = {
type?: string;
} | {
getType(): string;
getId(): string;
};
id?: string;
} | string | null;
export declare type Fact = [predicate: string, ...args: Instance[]];

@@ -26,4 +19,5 @@ export declare class Oso {

bulkDelete(facts: [predicate: string, ...args: Instance[]][]): Promise<void>;
get(predicate: string, ...args: (Instance | null)[]): Promise<Fact[]>;
get(predicate: string, ...args: Instance[]): Promise<Fact[]>;
query(predicate: string, ...args: Instance[]): Promise<Fact[]>;
}
//# sourceMappingURL=index.d.ts.map

@@ -24,4 +24,4 @@ "use strict";

}
let { type: actor_type, id: actor_id } = (0, helpers_1.getTypeAndId)(actor);
let { type: resource_type, id: resource_id } = (0, helpers_1.getTypeAndId)(resource);
let { type: actor_type, id: actor_id } = (0, helpers_1.toTypedId)(actor);
let { type: resource_type, id: resource_id } = (0, helpers_1.toTypedId)(resource);
let result = yield this.api.postAuthorize({

@@ -43,3 +43,3 @@ actor_type,

}
const { type: actor_type, id: actor_id } = (0, helpers_1.getTypeAndId)(actor);
const { type: actor_type, id: actor_id } = (0, helpers_1.toTypedId)(actor);
function key(e) {

@@ -51,3 +51,3 @@ return `${e.type}:${e.id}`;

}
const resourcesExtracted = resources.map((r) => (0, helpers_1.getTypeAndId)(r));
const resourcesExtracted = resources.map((r) => (0, helpers_1.toTypedId)(r));
const { results } = yield this.api.postAuthorizeResources({

@@ -70,3 +70,3 @@ actor_type,

}
return resources.filter((r) => resultsLookup[key((0, helpers_1.getTypeAndId)(r))]);
return resources.filter((r) => resultsLookup[key((0, helpers_1.toTypedId)(r))]);
});

@@ -78,3 +78,3 @@ }

throw new TypeError(`'action' should be a string: ${action}`);
const { type: actor_type, id: actor_id } = (0, helpers_1.getTypeAndId)(actor);
const { type: actor_type, id: actor_id } = (0, helpers_1.toTypedId)(actor);
const { results } = yield this.api.postList({

@@ -92,4 +92,4 @@ actor_type,

return __awaiter(this, void 0, void 0, function* () {
let { type: actor_type, id: actor_id } = (0, helpers_1.getTypeAndId)(actor);
let { type: resource_type, id: resource_id } = (0, helpers_1.getTypeAndId)(resource);
let { type: actor_type, id: actor_id } = (0, helpers_1.toTypedId)(actor);
let { type: resource_type, id: resource_id } = (0, helpers_1.toTypedId)(resource);
const { results } = yield this.api.postActions({

@@ -114,3 +114,3 @@ actor_type,

predicate,
args: args.map(helpers_1.getTypeAndId),
args: args.map(helpers_1.toTypedId),
});

@@ -123,3 +123,3 @@ });

predicate,
args: args.map(helpers_1.getTypeAndId),
args: args.map(helpers_1.toTypedId),
});

@@ -140,18 +140,23 @@ });

return __awaiter(this, void 0, void 0, function* () {
let idArgs = args.map((a) => (a ? (0, helpers_1.getTypeAndId)(a) : { type: "", id: "" }));
let facts = (0, helpers_1.mapFactsToParams)(yield this.api.getFacts(predicate, idArgs));
return facts.map(([pred, ...args]) => {
let compressed = args.map((a) => {
if (typeof a === "object" &&
"id" in a &&
"type" in a &&
a.type == "String") {
return a.id;
}
else {
return a;
}
});
return [pred, ...compressed];
let varArgs = args.map(helpers_1.toVariable);
let facts = (0, helpers_1.mapFactsToParams)(yield this.api.getFacts(predicate, varArgs));
return facts;
});
}
query(predicate, ...args) {
return __awaiter(this, void 0, void 0, function* () {
let varArgs = args.map(helpers_1.toVariable);
const { results } = yield this.api.postQuery({
fact: {
predicate,
args: varArgs,
},
context_facts: [],
});
if (!results)
return [];
return results.map((fact) => [
fact.predicate,
...fact.args.map(helpers_1.fromVariable),
]);
});

@@ -158,0 +163,0 @@ }

@@ -38,3 +38,3 @@ "use strict";

}
const oso = new _1.Oso("http://localhost:8080", "dF8wMTIzNDU2Nzg5Om9zb190ZXN0X3Rva2Vu");
const oso = new _1.Oso("http://localhost:8081", "e_0123456789_12345_osotesttoken01xiIn");
const policyDefault = `

@@ -50,8 +50,5 @@ actor User {

"read" if "member";
"read" if "read" on "parent";
}
`;
const user1 = new User(1);
const repo1 = new Repo(1);
const repo2 = new Repo(2);
const repo3 = new Repo(3);
describe("test authorize", () => {

@@ -62,11 +59,23 @@ beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {

afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
yield oso.delete("has_permission", user1, "read", repo3);
yield oso.delete("has_permission", { type: "User", id: "1" }, "read", {
type: "Repo",
id: "3",
});
}));
test("denied", () => __awaiter(void 0, void 0, void 0, function* () {
const authorize = yield oso.authorize(user1, "read", repo2);
const authorize = yield oso.authorize({ type: "User", id: "1" }, "read", {
type: "Repo",
id: "2",
});
expect(authorize).toEqual(false);
}));
test("allowed", () => __awaiter(void 0, void 0, void 0, function* () {
yield oso.tell("has_permission", user1, "read", repo3);
const authorize = yield oso.authorize(user1, "read", repo3);
yield oso.tell("has_permission", { type: "User", id: "1" }, "read", {
type: "Repo",
id: "3",
});
const authorize = yield oso.authorize({ type: "User", id: "1" }, "read", {
type: "Repo",
id: "3",
});
expect(authorize).toEqual(true);

@@ -76,8 +85,18 @@ }));

let contextFacts = [
["has_permission", user1, "read", repo3],
["has_permission", user1, "read", repo2],
[
"has_permission",
{ type: "User", id: "1" },
"read",
{ type: "Repo", id: "3" },
],
[
"has_permission",
{ type: "User", id: "1" },
"read",
{ type: "Repo", id: "2" },
],
];
const authorize = yield oso.authorize({ type: "User", id: user1.getId() }, "read", repo2, contextFacts);
const authorize = yield oso.authorize({ type: "User", id: "1" }, "read", { type: "Repo", id: "2" }, contextFacts);
expect(authorize).toEqual(true);
const authorize2 = yield oso.authorize(user1, "read", repo3, contextFacts);
const authorize2 = yield oso.authorize({ type: "User", id: "1" }, "read", { type: "Repo", id: "3" }, contextFacts);
expect(authorize).toEqual(true);

@@ -91,7 +110,13 @@ }));

afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
yield oso.delete("has_permission", user1, "read", repo3);
yield oso.delete("has_permission", user1, "read", repo2);
yield oso.delete("has_permission", { type: "User", id: "1" }, "read", {
type: "Repo",
id: "3",
});
yield oso.delete("has_permission", { type: "User", id: "1" }, "read", {
type: "Repo",
id: "2",
});
}));
test("empty", () => __awaiter(void 0, void 0, void 0, function* () {
const list = yield oso.list(user1, "read", "Repo");
const list = yield oso.list({ type: "User", id: "1" }, "read", "Repo");
expect(Array.isArray(list)).toBeTruthy();

@@ -101,25 +126,55 @@ expect(list.length).toEqual(0);

test("some", () => __awaiter(void 0, void 0, void 0, function* () {
yield oso.tell("has_permission", user1, "read", repo2);
yield oso.tell("has_permission", user1, "read", repo3);
const list = yield oso.list(user1, "read", "Repo");
yield oso.tell("has_permission", { type: "User", id: "1" }, "read", {
type: "Repo",
id: "2",
});
yield oso.tell("has_permission", { type: "User", id: "1" }, "read", {
type: "Repo",
id: "3",
});
const list = yield oso.list({ type: "User", id: "1" }, "read", "Repo");
expect(Array.isArray(list)).toBeTruthy();
expect(list.length).toEqual(2);
expect(list).toEqual(expect.arrayContaining([repo2.id.toString(), repo3.id.toString()]));
expect(list).toEqual(expect.arrayContaining([
{ type: "Repo", id: "2" }.id.toString(),
{ type: "Repo", id: "3" }.id.toString(),
]));
}));
test("context facts", () => __awaiter(void 0, void 0, void 0, function* () {
let contextFacts = [
["has_permission", user1, "read", repo2],
["has_permission", user1, "read", repo3],
[
"has_permission",
{ type: "User", id: "1" },
"read",
{ type: "Repo", id: "2" },
],
[
"has_permission",
{ type: "User", id: "1" },
"read",
{ type: "Repo", id: "3" },
],
];
const list = yield oso.list(user1, "read", "Repo", contextFacts);
const list = yield oso.list({ type: "User", id: "1" }, "read", "Repo", contextFacts);
expect(Array.isArray(list)).toBeTruthy();
expect(list.length).toEqual(2);
expect(list).toEqual(expect.arrayContaining([repo2.id.toString(), repo3.id.toString()]));
expect(list).toEqual(expect.arrayContaining([
{ type: "Repo", id: "2" }.id.toString(),
{ type: "Repo", id: "3" }.id.toString(),
]));
}));
});
describe("test actions", () => {
const fact = ["has_role", user1, "member", repo1];
const fact = [
"has_role",
{ type: "User", id: "1" },
"member",
{ type: "Repo", id: "1" },
];
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
yield oso.policy(policyDefault);
yield oso.tell("has_role", user1, "member", repo1);
yield oso.tell("has_role", { type: "User", id: "1" }, "member", {
type: "Repo",
id: "1",
});
}));

@@ -130,3 +185,3 @@ afterAll(() => __awaiter(void 0, void 0, void 0, function* () {

test("read", () => __awaiter(void 0, void 0, void 0, function* () {
const list = yield oso.actions(user1, repo1);
const list = yield oso.actions({ type: "User", id: "1" }, { type: "Repo", id: "1" });
expect(Array.isArray(list)).toBeTruthy();

@@ -137,3 +192,3 @@ expect(list.length).toEqual(1);

test("empty", () => __awaiter(void 0, void 0, void 0, function* () {
const list = yield oso.actions(user1, repo2);
const list = yield oso.actions({ type: "User", id: "1" }, { type: "Repo", id: "2" });
expect(Array.isArray(list)).toBeTruthy();

@@ -143,4 +198,9 @@ expect(list.length).toEqual(0);

test("context facts", () => __awaiter(void 0, void 0, void 0, function* () {
const list = yield oso.actions(user1, repo3, [
["has_role", user1, "member", repo3],
const list = yield oso.actions({ type: "User", id: "1" }, { type: "Repo", id: "3" }, [
[
"has_role",
{ type: "User", id: "1" },
"member",
{ type: "Repo", id: "3" },
],
]);

@@ -157,7 +217,13 @@ expect(Array.isArray(list)).toBeTruthy();

afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
yield oso.delete("has_role", user1, "member", repo2);
yield oso.delete("has_role", { type: "User", id: "1" }, "member", {
type: "Repo",
id: "2",
});
}));
test("has_role", () => __awaiter(void 0, void 0, void 0, function* () {
yield oso.tell("has_role", user1, "member", repo2);
const roles = yield oso.get("has_role", user1, "member", repo2);
yield oso.tell("has_role", { type: "User", id: "1" }, "member", {
type: "Repo",
id: "2",
});
const roles = yield oso.get("has_role", { type: "User", id: "1" }, "member", { type: "Repo", id: "2" });
expect(Array.isArray(roles)).toBeTruthy();

@@ -169,7 +235,13 @@ expect(roles.length).toEqual(1);

test("wildcards", () => __awaiter(void 0, void 0, void 0, function* () {
yield oso.tell("has_role", user1, "member", repo2);
let roles = yield oso.get("has_role", null, null, repo2);
yield oso.tell("has_role", { type: "User", id: "1" }, "member", {
type: "Repo",
id: "2",
});
let roles = yield oso.get("has_role", null, null, {
type: "Repo",
id: "2",
});
expect(Array.isArray(roles)).toBeTruthy();
expect(roles.length).toEqual(1);
roles = yield oso.get("has_role", null, null, user1);
roles = yield oso.get("has_role", null, null, { type: "User", id: "1" });
expect(Array.isArray(roles)).toBeTruthy();

@@ -181,4 +253,14 @@ expect(roles.length).toEqual(0);

const moreFacts = [
["has_role", user1, "member", repo2],
["has_relation", repo2, "parent", repo3],
[
"has_role",
{ type: "User", id: "1" },
"member",
{ type: "Repo", id: "2" },
],
[
"has_relation",
{ type: "Repo", id: "2" },
"parent",
{ type: "Repo", id: "3" },
],
];

@@ -193,6 +275,6 @@ beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {

yield oso.bulkTell(moreFacts);
const bulkRoles = yield oso.get("has_role", user1, "member", repo2);
const bulkRoles = yield oso.get("has_role", { type: "User", id: "1" }, "member", { type: "Repo", id: "2" });
expect(Array.isArray(bulkRoles)).toBeTruthy();
expect(bulkRoles.length).toEqual(1);
const bulkRelations = yield oso.get("has_relation", repo2, "parent", repo3);
const bulkRelations = yield oso.get("has_relation", { type: "Repo", id: "2" }, "parent", { type: "Repo", id: "3" });
expect(Array.isArray(bulkRelations)).toBeTruthy();

@@ -203,6 +285,6 @@ expect(bulkRelations.length).toEqual(1);

yield oso.bulkDelete(moreFacts);
const bulkDeleteRoles = yield oso.get("has_role", user1, "member", repo2);
const bulkDeleteRoles = yield oso.get("has_role", { type: "User", id: "1" }, "member", { type: "Repo", id: "2" });
expect(Array.isArray(bulkDeleteRoles)).toBeTruthy();
expect(bulkDeleteRoles.length).toEqual(0);
const bulkDeleteRelations = yield oso.get("has_relation", repo2, "parent", repo3);
const bulkDeleteRelations = yield oso.get("has_relation", { type: "Repo", id: "2" }, "parent", { type: "Repo", id: "3" });
expect(Array.isArray(bulkDeleteRelations)).toBeTruthy();

@@ -215,11 +297,23 @@ expect(bulkDeleteRelations.length).toEqual(0);

yield oso.policy(policyDefault);
yield oso.tell("has_role", user1, "member", repo1);
yield oso.tell("has_role", user1, "member", repo2);
yield oso.tell("has_role", { type: "User", id: "1" }, "member", {
type: "Repo",
id: "1",
});
yield oso.tell("has_role", { type: "User", id: "1" }, "member", {
type: "Repo",
id: "2",
});
}));
afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
yield oso.delete("has_role", user1, "member", repo1);
yield oso.delete("has_role", user1, "member", repo2);
yield oso.delete("has_role", { type: "User", id: "1" }, "member", {
type: "Repo",
id: "1",
});
yield oso.delete("has_role", { type: "User", id: "1" }, "member", {
type: "Repo",
id: "2",
});
}));
test("empty", () => __awaiter(void 0, void 0, void 0, function* () {
let res = yield oso.authorizeResources(user1, "read", []);
let res = yield oso.authorizeResources({ type: "User", id: "1" }, "read", []);
expect(Array.isArray(res)).toBeTruthy();

@@ -229,18 +323,96 @@ expect(res.length).toEqual(0);

test("match all", () => __awaiter(void 0, void 0, void 0, function* () {
const res = yield oso.authorizeResources(user1, "read", [repo1, repo2]);
expect(new Set(res)).toEqual(new Set([repo1, repo2]));
const res = yield oso.authorizeResources({ type: "User", id: "1" }, "read", [
{ type: "Repo", id: "1" },
{ type: "Repo", id: "2" },
]);
expect(new Set(res)).toEqual(new Set([
{ type: "Repo", id: "1" },
{ type: "Repo", id: "2" },
]));
}));
test("match some", () => __awaiter(void 0, void 0, void 0, function* () {
const res = yield oso.authorizeResources(user1, "read", [repo1, repo3]);
expect(new Set(res)).toEqual(new Set([repo1]));
const res = yield oso.authorizeResources({ type: "User", id: "1" }, "read", [
{ type: "Repo", id: "1" },
{ type: "Repo", id: "3" },
]);
expect(new Set(res)).toEqual(new Set([{ type: "Repo", id: "1" }]));
}));
test("match none", () => __awaiter(void 0, void 0, void 0, function* () {
const res = yield oso.authorizeResources(user1, "read", [repo3]);
const res = yield oso.authorizeResources({ type: "User", id: "1" }, "read", [{ type: "Repo", id: "3" }]);
expect(new Set(res)).toEqual(new Set([]));
}));
test("context facts", () => __awaiter(void 0, void 0, void 0, function* () {
const res = yield oso.authorizeResources(user1, "read", [repo1, repo2, repo3], [["has_role", user1, "member", repo3]]);
expect(new Set(res)).toEqual(new Set([repo1, repo2, repo3]));
const res = yield oso.authorizeResources({ type: "User", id: "1" }, "read", [
{ type: "Repo", id: "1" },
{ type: "Repo", id: "2" },
{ type: "Repo", id: "3" },
], [
[
"has_role",
{ type: "User", id: "1" },
"member",
{ type: "Repo", id: "3" },
],
]);
expect(new Set(res)).toEqual(new Set([
{ type: "Repo", id: "1" },
{ type: "Repo", id: "2" },
{ type: "Repo", id: "3" },
]));
}));
});
describe("test query", () => {
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
yield oso.policy(`
actor User {}
resource Computer {}
hello(friend) if
is_friendly(friend);
something_else(friend, other_friend, _anybody) if
is_friendly(friend) and is_friendly(other_friend);
`);
yield oso.tell("is_friendly", { type: "User", id: "sam" });
yield oso.tell("is_friendly", { type: "User", id: "gabe" });
yield oso.tell("is_friendly", { type: "Computer", id: "steve" });
}));
afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
yield oso.delete("is_friendly", { type: "User", id: "sam" });
yield oso.delete("is_friendly", { type: "User", id: "gabe" });
yield oso.delete("is_friendly", { type: "Computer", id: "steve" });
}));
test("query free", () => __awaiter(void 0, void 0, void 0, function* () {
let res = yield oso.query("hello", null);
expect(new Set(res)).toEqual(new Set([
["hello", { type: "User", id: "sam" }],
["hello", { type: "User", id: "gabe" }],
["hello", { type: "Computer", id: "steve" }],
]));
}));
test("query typed", () => __awaiter(void 0, void 0, void 0, function* () {
let res = yield oso.query("hello", { type: "User" });
expect(new Set(res)).toEqual(new Set([
["hello", { type: "User", id: "sam" }],
["hello", { type: "User", id: "gabe" }],
]));
}));
test("returns vars", () => __awaiter(void 0, void 0, void 0, function* () {
let res = yield oso.query("something_else", { type: "User" }, { type: "Computer" }, null);
expect(new Set(res)).toEqual(new Set([
[
"something_else",
{ type: "User", id: "sam" },
{ type: "Computer", id: "steve" },
null,
],
[
"something_else",
{ type: "User", id: "gabe" },
{ type: "Computer", id: "steve" },
null,
],
]));
}));
});
//# sourceMappingURL=index.test.js.map
{
"name": "oso-cloud",
"version": "0.7.0",
"version": "0.8.0-alpha.1",
"description": "Client library for Oso Cloud",

@@ -40,2 +40,2 @@ "main": "dist/index.js",

}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc