Repository navigation
fix(service): require authentication for push/repo/user read APIs and trim file-sink push list (sfind-0d184eca) #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a607bd8
0f38600
6f6df9b
400ee6a
3cbb2b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Copyright 2026 GitProxy Contributors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { Request, Response, NextFunction } from 'express'; | ||
|
|
||
| /** | ||
| * Reject unauthenticated requests. Accepts either a passport session | ||
| * (req.isAuthenticated()) or a request that a prior auth handler (e.g. JWT) | ||
| * has populated with req.user. | ||
| */ | ||
| export const ensureAuthenticated = (req: Request, res: Response, next: NextFunction): void => { | ||
| const sessionAuthed = typeof req.isAuthenticated === 'function' && req.isAuthenticated(); | ||
| if (sessionAuthed || req.user) { | ||
| return next(); | ||
| } | ||
| res.status(401).send({ message: 'Authentication required' }); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏱️ TD API Contracts: Authentication errors omit required problem details For unauthenticated push, repository, and user requests, View in Devin Review · Custom reviewer Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /** | ||
| * Copyright 2026 GitProxy Contributors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import express, { Express, Request, Response, NextFunction } from 'express'; | ||
| import request from 'supertest'; | ||
| import rateLimit from 'express-rate-limit'; | ||
| import { ensureAuthenticated } from '../../../src/service/routes/middleware'; | ||
| import { jwtAuthHandler } from '../../../src/service/passport/jwtAuthHandler'; | ||
| import usersRouter from '../../../src/service/routes/users'; | ||
|
|
||
| describe('ensureAuthenticated', () => { | ||
| const buildRes = () => { | ||
| const res = {} as Response; | ||
| res.status = vi.fn().mockReturnValue(res); | ||
| res.send = vi.fn().mockReturnValue(res); | ||
| return res; | ||
| }; | ||
|
|
||
| it('calls next() for a passport session authenticated request', () => { | ||
| const req = { isAuthenticated: () => true } as unknown as Request; | ||
| const res = buildRes(); | ||
| const next = vi.fn() as unknown as NextFunction; | ||
|
|
||
| ensureAuthenticated(req, res, next); | ||
|
|
||
| expect(next).toHaveBeenCalledOnce(); | ||
| expect(res.status).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('calls next() for a request populated with req.user (e.g. JWT)', () => { | ||
| const req = { | ||
| isAuthenticated: () => false, | ||
| user: { username: 'api-client' }, | ||
| } as unknown as Request; | ||
| const res = buildRes(); | ||
| const next = vi.fn() as unknown as NextFunction; | ||
|
|
||
| ensureAuthenticated(req, res, next); | ||
|
|
||
| expect(next).toHaveBeenCalledOnce(); | ||
| expect(res.status).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('responds 401 when there is no session and no req.user', () => { | ||
| const req = { isAuthenticated: () => false } as unknown as Request; | ||
| const res = buildRes(); | ||
| const next = vi.fn() as unknown as NextFunction; | ||
|
|
||
| ensureAuthenticated(req, res, next); | ||
|
|
||
| expect(next).not.toHaveBeenCalled(); | ||
| expect(res.status).toHaveBeenCalledWith(401); | ||
| expect(res.send).toHaveBeenCalledWith({ message: 'Authentication required' }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('GET /api/v1/user authentication', () => { | ||
| let app: Express; | ||
|
|
||
| // Mirror the mount in src/service/routes/index.ts (jwtAuthHandler then ensureAuthenticated). | ||
| const buildApp = (): Express => { | ||
| const a = express(); | ||
| a.use(rateLimit({ windowMs: 60 * 1000, limit: 100 })); | ||
| a.use(express.json()); | ||
| a.use('/api/v1/user', jwtAuthHandler(), ensureAuthenticated, usersRouter); | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| return a; | ||
| }; | ||
|
|
||
| it('returns 401 when unauthenticated', async () => { | ||
| app = buildApp(); | ||
| const res = await request(app).get('/api/v1/user'); | ||
|
|
||
| expect(res.status).toBe(401); | ||
| expect(res.body.message).toBe('Authentication required'); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⏱️ TD API Contracts: Push list drops existing v1 fields
For file-sink lists,
getPusheschanges v1 records from full actions to summaries withoutattestation,autoApproved, orlastStep. getGitPushes still prints these fields, so CLI users now receiveundefinedinstead of approval and diagnostic data. Dropping existing response fields within v1 violates §4 compatibility.View in Devin Review · Custom reviewer
Was this helpful? React with 👍 or 👎 to provide feedback.