Skip to content

Commit 07e8ce9

Browse files
committed
Fix router test after metadata key removed
1 parent 48cddd9 commit 07e8ce9

File tree

1 file changed

+24
-42
lines changed

1 file changed

+24
-42
lines changed

src/server/auth/router.test.ts

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('MCP Auth Router', () => {
1818
}
1919
return undefined;
2020
},
21-
21+
2222
async registerClient(client: OAuthClientInformationFull): Promise<OAuthClientInformationFull> {
2323
return client;
2424
}
@@ -114,71 +114,59 @@ describe('MCP Auth Router', () => {
114114
it('throws error for non-HTTPS issuer URL', () => {
115115
const options: AuthRouterOptions = {
116116
provider: mockProvider,
117-
metadata: {
118-
issuerUrl: new URL('http://auth.example.com')
119-
}
117+
issuerUrl: new URL('http://auth.example.com')
120118
};
121-
119+
122120
expect(() => mcpAuthRouter(options)).toThrow('Issuer URL must be HTTPS');
123121
});
124122

125123
it('allows localhost HTTP for development', () => {
126124
const options: AuthRouterOptions = {
127125
provider: mockProvider,
128-
metadata: {
129-
issuerUrl: new URL('http://localhost:3000')
130-
}
126+
issuerUrl: new URL('http://localhost:3000')
131127
};
132-
128+
133129
expect(() => mcpAuthRouter(options)).not.toThrow();
134130
});
135131

136132
it('throws error for issuer URL with fragment', () => {
137133
const options: AuthRouterOptions = {
138134
provider: mockProvider,
139-
metadata: {
140-
issuerUrl: new URL('https://auth.example.com#fragment')
141-
}
135+
issuerUrl: new URL('https://auth.example.com#fragment')
142136
};
143-
137+
144138
expect(() => mcpAuthRouter(options)).toThrow('Issuer URL must not have a fragment');
145139
});
146140

147141
it('throws error for issuer URL with query string', () => {
148142
const options: AuthRouterOptions = {
149143
provider: mockProvider,
150-
metadata: {
151-
issuerUrl: new URL('https://auth.example.com?param=value')
152-
}
144+
issuerUrl: new URL('https://auth.example.com?param=value')
153145
};
154-
146+
155147
expect(() => mcpAuthRouter(options)).toThrow('Issuer URL must not have a query string');
156148
});
157149

158150
it('successfully creates router with valid options', () => {
159151
const options: AuthRouterOptions = {
160152
provider: mockProvider,
161-
metadata: {
162-
issuerUrl: new URL('https://auth.example.com')
163-
}
153+
issuerUrl: new URL('https://auth.example.com')
164154
};
165-
155+
166156
expect(() => mcpAuthRouter(options)).not.toThrow();
167157
});
168158
});
169159

170160
describe('Metadata endpoint', () => {
171161
let app: express.Express;
172-
162+
173163
beforeEach(() => {
174164
// Setup full-featured router
175165
app = express();
176166
const options: AuthRouterOptions = {
177167
provider: mockProvider,
178-
metadata: {
179-
issuerUrl: new URL('https://auth.example.com'),
180-
serviceDocumentationUrl: new URL('https://docs.example.com')
181-
}
168+
issuerUrl: new URL('https://auth.example.com'),
169+
serviceDocumentationUrl: new URL('https://docs.example.com')
182170
};
183171
app.use(mcpAuthRouter(options));
184172
});
@@ -188,21 +176,21 @@ describe('MCP Auth Router', () => {
188176
.get('/.well-known/oauth-authorization-server');
189177

190178
expect(response.status).toBe(200);
191-
179+
192180
// Verify essential fields
193181
expect(response.body.issuer).toBe('https://auth.example.com/');
194182
expect(response.body.authorization_endpoint).toBe('https://auth.example.com/authorize');
195183
expect(response.body.token_endpoint).toBe('https://auth.example.com/token');
196184
expect(response.body.registration_endpoint).toBe('https://auth.example.com/register');
197185
expect(response.body.revocation_endpoint).toBe('https://auth.example.com/revoke');
198-
186+
199187
// Verify supported features
200188
expect(response.body.response_types_supported).toEqual(['code']);
201189
expect(response.body.grant_types_supported).toEqual(['authorization_code', 'refresh_token']);
202190
expect(response.body.code_challenge_methods_supported).toEqual(['S256']);
203191
expect(response.body.token_endpoint_auth_methods_supported).toEqual(['client_secret_post']);
204192
expect(response.body.revocation_endpoint_auth_methods_supported).toEqual(['client_secret_post']);
205-
193+
206194
// Verify optional fields
207195
expect(response.body.service_documentation).toBe('https://docs.example.com/');
208196
});
@@ -212,22 +200,20 @@ describe('MCP Auth Router', () => {
212200
const minimalApp = express();
213201
const options: AuthRouterOptions = {
214202
provider: mockProviderMinimal,
215-
metadata: {
216-
issuerUrl: new URL('https://auth.example.com')
217-
}
203+
issuerUrl: new URL('https://auth.example.com')
218204
};
219205
minimalApp.use(mcpAuthRouter(options));
220206

221207
const response = await supertest(minimalApp)
222208
.get('/.well-known/oauth-authorization-server');
223209

224210
expect(response.status).toBe(200);
225-
211+
226212
// Verify essential endpoints
227213
expect(response.body.issuer).toBe('https://auth.example.com/');
228214
expect(response.body.authorization_endpoint).toBe('https://auth.example.com/authorize');
229215
expect(response.body.token_endpoint).toBe('https://auth.example.com/token');
230-
216+
231217
// Verify missing optional endpoints
232218
expect(response.body.registration_endpoint).toBeUndefined();
233219
expect(response.body.revocation_endpoint).toBeUndefined();
@@ -238,15 +224,13 @@ describe('MCP Auth Router', () => {
238224

239225
describe('Endpoint routing', () => {
240226
let app: express.Express;
241-
227+
242228
beforeEach(() => {
243229
// Setup full-featured router
244230
app = express();
245231
const options: AuthRouterOptions = {
246232
provider: mockProvider,
247-
metadata: {
248-
issuerUrl: new URL('https://auth.example.com')
249-
}
233+
issuerUrl: new URL('https://auth.example.com')
250234
};
251235
app.use(mcpAuthRouter(options));
252236
});
@@ -271,7 +255,7 @@ describe('MCP Auth Router', () => {
271255
jest.mock('pkce-challenge', () => ({
272256
verifyChallenge: jest.fn().mockResolvedValue(true)
273257
}));
274-
258+
275259
const response = await supertest(app)
276260
.post('/token')
277261
.type('form')
@@ -320,9 +304,7 @@ describe('MCP Auth Router', () => {
320304
const minimalApp = express();
321305
const options: AuthRouterOptions = {
322306
provider: mockProviderMinimal,
323-
metadata: {
324-
issuerUrl: new URL('https://auth.example.com')
325-
}
307+
issuerUrl: new URL('https://auth.example.com')
326308
};
327309
minimalApp.use(mcpAuthRouter(options));
328310

0 commit comments

Comments
 (0)