Skip to content

Commit 778717d

Browse files
committed
update authorizer
1 parent e18c08e commit 778717d

File tree

4 files changed

+113
-5
lines changed

4 files changed

+113
-5
lines changed

__tests__/authorizer/index.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ describe("ListPolicies", () => {
391391
const result = await authorizer.ListPolicies({});
392392
expect(result).toEqual([
393393
{
394-
$typeName: "aserto.authorizer.v2.api.Module",
395394
id: "1",
396395
packagePath: "a.b.c",
397396
},

__tests__/integration/index.test.ts

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ types:
17331733
policyContext: policyContext(),
17341734
});
17351735

1736-
expect(response).toEqual({
1736+
const expectedResult = {
17371737
path: {
17381738
"rebac.check": {
17391739
allowed: false,
@@ -1745,7 +1745,102 @@ types:
17451745
"todoApp.PUT.todos.__id": { allowed: false },
17461746
},
17471747
pathRoot: "",
1748+
};
1749+
1750+
expect(response).toEqual(expectedResult);
1751+
expect(JSON.parse(JSON.stringify(response))).toEqual(expectedResult);
1752+
});
1753+
});
1754+
1755+
describe("Is", () => {
1756+
it("returns the correct data structure", async () => {
1757+
const response = await authorizerClient.Is({
1758+
identityContext: await AnonymousIdentityMapper(),
1759+
policyInstance: policyInstance("todo", "todo"),
1760+
policyContext: policyContext("todoApp.GET.todos"),
1761+
});
1762+
1763+
const expectedResult = true;
1764+
1765+
expect(response).toEqual(expectedResult);
1766+
expect(JSON.parse(JSON.stringify(response))).toEqual(expectedResult);
1767+
});
1768+
});
1769+
1770+
describe("Query", () => {
1771+
it("returns the correct data structure", async () => {
1772+
const response = await authorizerClient.Query({
1773+
query: "x=data",
1774+
input: '{"foo": "bar"}',
1775+
});
1776+
1777+
const expectedResult = {
1778+
result: [
1779+
{
1780+
bindings: {
1781+
x: {
1782+
rebac: { check: { allowed: false } },
1783+
todoApp: {
1784+
DELETE: { todos: { __id: { allowed: false } } },
1785+
GET: {
1786+
todos: { allowed: true },
1787+
users: { __userID: { allowed: true } },
1788+
},
1789+
POST: { todos: { allowed: false } },
1790+
PUT: { todos: { __id: { allowed: false } } },
1791+
common: {},
1792+
},
1793+
},
1794+
},
1795+
expressions: [
1796+
{ location: { col: 1, row: 1 }, text: "x=data", value: true },
1797+
],
1798+
},
1799+
],
1800+
};
1801+
1802+
expect(response).toEqual(expectedResult);
1803+
expect(JSON.parse(JSON.stringify(response))).toEqual(expectedResult);
1804+
});
1805+
});
1806+
1807+
describe("ListPolicies", () => {
1808+
it("returns the correct data structure", async () => {
1809+
const response = await authorizerClient.ListPolicies({
1810+
policyInstance: {
1811+
name: "todo",
1812+
},
1813+
fieldMask: {
1814+
paths: ["id"],
1815+
},
17481816
});
1817+
1818+
const expectedResult = [
1819+
{
1820+
id: "todo/github/workspace/content/src/policies/todoApp.DELETE.todos.__id.rego",
1821+
},
1822+
{
1823+
id: "todo/github/workspace/content/src/policies/todoApp.GET.todos.rego",
1824+
},
1825+
{
1826+
id: "todo/github/workspace/content/src/policies/todoApp.GET.users.__userID.rego",
1827+
},
1828+
{
1829+
id: "todo/github/workspace/content/src/policies/todoApp.POST.todos.rego",
1830+
},
1831+
{
1832+
id: "todo/github/workspace/content/src/policies/todoApp.PUT.todos.__id.rego",
1833+
},
1834+
{
1835+
id: "todo/github/workspace/content/src/policies/todoApp.common.rego",
1836+
},
1837+
{ id: "todo/github/workspace/content/src/policies/rebac.check.rego" },
1838+
];
1839+
1840+
expect(response).toEqual(expect.arrayContaining(expectedResult));
1841+
expect(JSON.parse(JSON.stringify(response))).toEqual(
1842+
expect.arrayContaining(expectedResult),
1843+
);
17491844
});
17501845
});
17511846
});

lib/authorizer/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { readFileSync } from "fs";
2-
import { Module } from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/module_pb";
32
import {
43
Authorizer as AuthorizerClient,
54
DecisionTreeRequestSchema,
@@ -26,6 +25,7 @@ import {
2625
DecisionTreeRequest,
2726
IsRequest,
2827
ListPoliciesRequest,
28+
Module,
2929
QueryRequest,
3030
} from "./types";
3131

@@ -151,7 +151,10 @@ export class Authorizer {
151151
try {
152152
const response = await this.AuthClient.listPolicies(params, options);
153153

154-
return response.result;
154+
return response.result.map((res) => {
155+
const { $typeName: _t, ...result } = res;
156+
return result;
157+
});
155158
} catch (error) {
156159
throw handleError(error, "ListPolicies");
157160
}

lib/authorizer/types.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
QueryOptions as QueryOptions$,
99
QueryRequest as QueryRequest$,
1010
} from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/authorizer_pb";
11+
import { FieldMask as FieldMask$ } from "@bufbuild/protobuf/wkt";
1112

1213
import { Optional } from "../util/types";
1314

@@ -16,6 +17,7 @@ export * from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/iden
1617
export * from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/policy_context_pb";
1718
export * from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/policy_instance_pb";
1819
export * from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/module_pb";
20+
import { Module as Module$ } from "@aserto/node-authorizer/src/gen/cjs/aserto/authorizer/v2/api/module_pb";
1921
export {
2022
Decision as DecisionLog,
2123
DecisionSchema as DecisionLogSchema,
@@ -68,4 +70,13 @@ export type DecisionTreeRequest = Omit<
6870
identityContext?: IdentityContext;
6971
};
7072

71-
export type ListPoliciesRequest = Omit<ListPoliciesRequest$, "$typeName">;
73+
export type FieldMask = Omit<FieldMask$, "$typeName">;
74+
export type ListPoliciesRequest = Omit<
75+
ListPoliciesRequest$,
76+
"$typeName" | "fieldMask" | "policyInstance"
77+
> & {
78+
fieldMask?: FieldMask;
79+
policyInstance?: PolicyInstance;
80+
};
81+
82+
export type Module = Omit<Module$, "$typeName">;

0 commit comments

Comments
 (0)