-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
345 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import express, { Express } from "express"; | ||
import nJwt from "njwt"; | ||
import request from "supertest"; | ||
|
||
import { | ||
AnonymousIdentityMapper, | ||
Authorizer, | ||
createAsyncIterable, | ||
DirectoryServiceV3, | ||
DirectoryV3, | ||
displayStateMap, | ||
EtagMismatchError, | ||
ImportMsgCase, | ||
ImportOpCode, | ||
|
@@ -502,7 +507,7 @@ types: | |
beforeEach(async () => { | ||
authorizerClient = new Authorizer({ | ||
authorizerServiceUrl: "localhost:8282", | ||
authorizerCertFile: await topaz.caCert(), | ||
caFile: await topaz.caCert(), | ||
}); | ||
}); | ||
|
||
|
@@ -530,4 +535,108 @@ types: | |
}); | ||
}); | ||
}); | ||
|
||
describe("DisplayStateMap", () => { | ||
const app: Express = express(); | ||
const jwt = nJwt.create({ sub: "[email protected]" }, "signingKey"); | ||
|
||
it("returns the correct data", async () => { | ||
const options = { | ||
policyRoot: "todoApp", | ||
instanceLabel: "todo", | ||
instanceName: "todo", | ||
authorizerServiceUrl: "localhost:8282", | ||
caFile: await topaz.caCert(), | ||
failWithError: true, | ||
}; | ||
app.use( | ||
displayStateMap( | ||
options, | ||
undefined, | ||
() => { | ||
return AnonymousIdentityMapper(); | ||
}, | ||
() => { | ||
return new Promise((resolve) => { | ||
resolve(policyContext("todoApp", ["allowed"])); | ||
}); | ||
} | ||
) | ||
); | ||
|
||
const response = await request(app) | ||
.get("/__displaystatemap") | ||
.set("Content-type", "application/json") | ||
.set("Authorization", `Bearer ${jwt}`); | ||
expect(response.body).toEqual({ | ||
"todoApp/DELETE/todos/__id": { | ||
allowed: false, | ||
}, | ||
"todoApp/GET/todos": { | ||
allowed: true, | ||
}, | ||
"todoApp/GET/users/__userID": { | ||
allowed: true, | ||
}, | ||
"todoApp/POST/todos": { | ||
allowed: false, | ||
}, | ||
"todoApp/PUT/todos/__id": { | ||
allowed: false, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("DisplayStateMap Legacy `authorizerCertCAFile`", () => { | ||
const app: Express = express(); | ||
const jwt = nJwt.create({ sub: "[email protected]" }, "signingKey"); | ||
|
||
it("returns the correct data", async () => { | ||
const options = { | ||
policyRoot: "todoApp", | ||
instanceLabel: "todo", | ||
instanceName: "todo", | ||
authorizerServiceUrl: "localhost:8282", | ||
authorizerCertCAFile: await topaz.caCert(), | ||
failWithError: true, | ||
}; | ||
app.use( | ||
displayStateMap( | ||
options, | ||
undefined, | ||
() => { | ||
return AnonymousIdentityMapper(); | ||
}, | ||
() => { | ||
return new Promise((resolve) => { | ||
resolve(policyContext("todoApp", ["allowed"])); | ||
}); | ||
} | ||
) | ||
); | ||
|
||
const response = await request(app) | ||
.get("/__displaystatemap") | ||
.set("Content-type", "application/json") | ||
.set("Authorization", `Bearer ${jwt}`); | ||
expect(response.body).toEqual({ | ||
"todoApp/DELETE/todos/__id": { | ||
allowed: false, | ||
}, | ||
"todoApp/GET/todos": { | ||
allowed: true, | ||
}, | ||
"todoApp/GET/users/__userID": { | ||
allowed: true, | ||
}, | ||
"todoApp/POST/todos": { | ||
allowed: false, | ||
}, | ||
"todoApp/PUT/todos/__id": { | ||
allowed: false, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.