Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/db/file/pushes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,34 @@ const defaultPushQuery: Partial<PushQuery> = {
type: 'push',
};

const pushListProjection = {
_id: 0,
id: 1,
allowPush: 1,
authorised: 1,
blocked: 1,
blockedMessage: 1,
branch: 1,
canceled: 1,
commitData: 1,
commitFrom: 1,
commitTo: 1,
error: 1,
method: 1,
project: 1,
rejected: 1,
repo: 1,
repoName: 1,
timestamp: 1,
type: 1,
url: 1,
};

export const getPushes = (query: Partial<PushQuery>): Promise<Action[]> => {
if (!query) query = defaultPushQuery;
return new Promise((resolve, reject) => {
db.find(query)
.projection(pushListProjection)

Copy link
Copy Markdown
Author

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, getPushes changes v1 records from full actions to summaries without attestation, autoApproved, or lastStep. getGitPushes still prints these fields, so CLI users now receive undefined instead of approval and diagnostic data. Dropping existing response fields within v1 violates §4 compatibility.

View in Devin Review · Custom reviewer

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

.sort({ timestamp: -1 })
.exec((err, docs) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
Expand Down
7 changes: 4 additions & 3 deletions src/service/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ import users from './users';
import healthcheck from './healthcheck';
import config from './config';
import { jwtAuthHandler } from '../passport/jwtAuthHandler';
import { ensureAuthenticated } from './middleware';
import { Proxy } from '../../proxy';

const routes = (proxy: Proxy) => {
const router = express.Router();
router.use('/api', home);
router.use('/api/auth', auth.router);
router.use('/api/v1/healthcheck', healthcheck);
router.use('/api/v1/push', jwtAuthHandler(), push);
router.use('/api/v1/repo', jwtAuthHandler(), repo(proxy));
router.use('/api/v1/user', jwtAuthHandler(), users);
router.use('/api/v1/push', jwtAuthHandler(), ensureAuthenticated, push);
router.use('/api/v1/repo', jwtAuthHandler(), ensureAuthenticated, repo(proxy));
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
router.use('/api/v1/user', jwtAuthHandler(), ensureAuthenticated, users);
router.use('/api/v1/config', config);
return router;
};
Expand Down
30 changes: 30 additions & 0 deletions src/service/routes/middleware.ts
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' });

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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, ensureAuthenticated returns application/json containing only {"message":"Authentication required"}. §4 requires RFC 9457 application/problem+json with a <DOMAIN>-<4 digits> code and correlationId. API clients receive neither the required error code nor a correlation identifier.

View in Devin Review · Custom reviewer

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

};
14 changes: 1 addition & 13 deletions src/ui/views/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import CardBody from '../../components/Card/CardBody';
import CardFooter from '../../components/Card/CardFooter';
import axios, { AxiosError } from 'axios';
import logo from '../../assets/img/git-proxy.png';
import { Badge, CircularProgress, FormLabel, Snackbar } from '@material-ui/core';
import { CircularProgress, FormLabel, Snackbar } from '@material-ui/core';
import { useAuth } from '../../auth/AuthProvider';
import { getBaseUrl } from '../../services/apiConfig';
import { getAxiosConfig, processAuthError } from '../../services/auth';
Expand Down Expand Up @@ -225,18 +225,6 @@ const Login: React.FC = () => {
)}
</CardFooter>
</Card>
<div style={{ textAlign: 'center', opacity: 0.9, fontSize: 12, marginTop: 20 }}>
<Badge
overlap='rectangular'
color='error'
badgeContent='NEW'
style={{ marginRight: 20 }}
/>
<span style={{ paddingLeft: 20 }}>
View our <a href='/dashboard/push'>open source activity feed</a> or{' '}
<a href='/dashboard/repo'>scroll through projects</a> we contribute to
</span>
</div>
</GridItem>
</GridContainer>
</form>
Expand Down
90 changes: 90 additions & 0 deletions test/services/routes/middleware.test.ts
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);
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
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');
});
});
16 changes: 14 additions & 2 deletions test/testDb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,22 @@ describe('Database clients', () => {
});

it('should be able to create a push', async () => {
await db.writeAudit(TEST_PUSH);
const push = await db.getPush(TEST_PUSH.id);
const cleanPush = cleanResponseData(TEST_PUSH, push!);
expect(cleanPush).toEqual(TEST_PUSH);
}, 20000);

it('should omit steps, user details and attestation when listing pushes', async () => {
await db.writeAudit(TEST_PUSH);
const pushes = await db.getPushes({});
const cleanPushes = cleanResponseData(TEST_PUSH, pushes);
expect(cleanPushes).toContainEqual(TEST_PUSH);
const push = pushes.find((p) => p.id === TEST_PUSH.id);
expect(push).toBeDefined();
expect(push).toHaveProperty('repo', TEST_PUSH.repo);
expect(push).not.toHaveProperty('steps');
expect(push).not.toHaveProperty('user');
expect(push).not.toHaveProperty('userEmail');
expect(push).not.toHaveProperty('attestation');
}, 20000);

it('should be able to delete a push', async () => {
Expand Down
35 changes: 30 additions & 5 deletions test/testPush.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ describe('Push API', () => {
.post(`/api/v1/push/${TEST_PUSH.id}/authorise`)
.send({ reason: 'Testing approval' });
expect(res.status).toBe(401);
expect(res.body.message).toBe('Not logged in');
expect(res.body.message).toBe('Authentication required');
});

it('should allow an authorizer to reject a push', async () => {
Expand Down Expand Up @@ -457,7 +457,22 @@ describe('Push API', () => {
.post(`/api/v1/push/${TEST_PUSH.id}/reject`)
.send({ reason: 'Testing rejection' });
expect(res.status).toBe(401);
expect(res.body.message).toBe('Not logged in');
expect(res.body.message).toBe('Authentication required');
});

it('should return 401 if not logged in when listing pushes', async () => {
await db.writeAudit(TEST_PUSH);
const res = await request(app).get('/api/v1/push').query({ blocked: true });
expect(res.status).toBe(401);
expect(res.body.message).toBe('Authentication required');
expect(JSON.stringify(res.body)).not.toContain(TEST_PUSH.id);
});

it('should return 401 if not logged in when fetching a push by id', async () => {
await db.writeAudit(TEST_PUSH);
const res = await request(app).get(`/api/v1/push/${TEST_PUSH.id}`);
expect(res.status).toBe(401);
expect(res.body.message).toBe('Authentication required');
});

it('should fetch all pushes', async () => {
Expand All @@ -470,9 +485,19 @@ describe('Push API', () => {
const push = res.body.find((p: Action) => p.id === TEST_PUSH.id);
expect(push).toBeDefined();

// Check that all values in push are in TEST_PUSH, except for _id
expect(push).toMatchObject(TEST_PUSH);
expect(push.repo).toBe(TEST_PUSH.repo);
expect(push.canceled).toBe(false);
expect(push).not.toHaveProperty('steps');
expect(push).not.toHaveProperty('user');
expect(push).not.toHaveProperty('userEmail');
expect(push).not.toHaveProperty('attestation');

const detail = await request(app)
.get(`/api/v1/push/${TEST_PUSH.id}`)
.set('Cookie', `${cookie}`);
expect(detail.status).toBe(200);
// Check that all values in push are in TEST_PUSH, except for _id
expect(detail.body).toMatchObject(TEST_PUSH);
});

it('should admit filter options when fetching pushes', async () => {
Expand Down Expand Up @@ -536,6 +561,6 @@ describe('Push API', () => {
.post(`/api/v1/push/${TEST_PUSH.id}/cancel`)
.send({ reason: 'Testing rejection' });
expect(res.status).toBe(401);
expect(res.body.message).toBe('Not logged in');
expect(res.body.message).toBe('Authentication required');
});
});
12 changes: 6 additions & 6 deletions test/testRepoApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ describe('repo routes - edge cases', () => {
});

expect(res.status).toBe(401);
expect(res.body.message).toBe('You are not authorised to perform this action.');
expect(res.body.message).toBe('Authentication required');
});

it('should return 400 when repo url is missing', async () => {
Expand Down Expand Up @@ -534,7 +534,7 @@ describe('repo routes - edge cases', () => {
.send({ username: 'testuser' });

expect(res.status).toBe(401);
expect(res.body.message).toBe('You are not authorised to perform this action.');
expect(res.body.message).toBe('Authentication required');
});

it('should return 401 when non-admin user tries to add authorise user', async () => {
Expand All @@ -553,7 +553,7 @@ describe('repo routes - edge cases', () => {
.send({ username: 'testuser' });

expect(res.status).toBe(401);
expect(res.body.message).toBe('You are not authorised to perform this action.');
expect(res.body.message).toBe('Authentication required');
});

describe('DELETE /api/v1/repo/:id/user/push/:username', () => {
Expand All @@ -576,7 +576,7 @@ describe('repo routes - edge cases', () => {
const res = await request(app).delete(`/api/v1/repo/${repoId}/user/push/testuser`).send();

expect(res.status).toBe(401);
expect(res.body.message).toBe('You are not authorised to perform this action.');
expect(res.body.message).toBe('Authentication required');
});

it('should return 400 when trying to remove non-existent user', async () => {
Expand Down Expand Up @@ -612,7 +612,7 @@ describe('repo routes - edge cases', () => {
.send();

expect(res.status).toBe(401);
expect(res.body.message).toBe('You are not authorised to perform this action.');
expect(res.body.message).toBe('Authentication required');
});

it('should return 400 when trying to remove non-existent user', async () => {
Expand Down Expand Up @@ -641,7 +641,7 @@ describe('repo routes - edge cases', () => {
const res = await request(app).delete(`/api/v1/repo/${repoId}/delete`).send();

expect(res.status).toBe(401);
expect(res.body.message).toBe('You are not authorised to perform this action.');
expect(res.body.message).toBe('Authentication required');
});
});

Expand Down
Loading