-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathoauth.test.ts
55 lines (48 loc) · 1.63 KB
/
oauth.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { describe, it } from "node:test";
import type { TestContext } from "node:test";
import app from "./index";
describe("OAuth", () => {
it(
"Can GET /.well-known/oauth-authorization-server",
{ plan: 10 },
async (t: TestContext) => {
// We use the full URL in this test as the route calculates values based
// on the Host header
const response = await app.request(
"http://localhost:3000/.well-known/oauth-authorization-server",
{
method: "GET",
},
);
t.assert.equal(response.status, 200, "Should return 200-ok");
const metadata = await response.json();
t.assert.equal(metadata.issuer, "http://localhost:3000/");
t.assert.equal(
metadata.authorization_endpoint,
"http://localhost:3000/oauth/authorize",
);
t.assert.equal(
metadata.token_endpoint,
"http://localhost:3000/oauth/token",
);
// Non-standard, mastodon extension:
t.assert.equal(
metadata.app_registration_endpoint,
"http://localhost:3000/api/v1/apps",
);
t.assert.deepStrictEqual(metadata.response_types_supported, ["code"]);
t.assert.deepStrictEqual(metadata.response_modes_supported, ["query"]);
t.assert.deepStrictEqual(metadata.grant_types_supported, [
"authorization_code",
"client_credentials",
]);
t.assert.deepStrictEqual(metadata.token_endpoint_auth_methods_supported, [
"client_secret_post",
]);
t.assert.ok(
Array.isArray(metadata.scopes_supported),
"Should return an array of scopes supported",
);
},
);
});