Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cd67c95
fix: add indexes, compaction and consistent lowercasing of inputs in …
kriswest Mar 25, 2025
1174c07
fix: consistent lowercasing of inputs in mongoDB implementation
kriswest Mar 25, 2025
c981a8f
fix: make repo name index non-unique (currently assumed unique but wo…
kriswest Mar 25, 2025
82ef441
fix: add indexes, compaction and consistent lowercasing of inputs in …
kriswest Mar 25, 2025
e129964
chore: porting changes from users.js
kriswest Apr 8, 2025
44b6c51
fix: bad merge
kriswest Apr 10, 2025
c81f829
fix: add indexes, compaction and consistent lowercasing of inputs in …
kriswest Mar 25, 2025
1847c0a
test: use unique emails for users in tests and remove afterwards
kriswest Apr 1, 2025
ab80338
fix: add indexes, compaction and consistent lowercasing of inputs in …
kriswest Mar 25, 2025
c778324
fix: consistent lowercasing of inputs in mongoDB implementation
kriswest Mar 25, 2025
7040595
chore: porting changes from users.js
kriswest Apr 8, 2025
c769769
fix: bad merge
kriswest Apr 10, 2025
0edd4db
fix: remove incorrect default query from repos page (that is ignored …
kriswest Mar 21, 2025
dd4fad0
fix: passthrough repository queries
kriswest Mar 25, 2025
ed578c1
test: more code coverage in DB and service/routes/repo
kriswest Apr 16, 2025
2280811
test: more DB test coverage
kriswest Apr 17, 2025
6ec8062
chore: extended prettier format command to package/git-proxy-cli and …
kriswest May 7, 2025
cab58e1
feat(key on repo url): start of db refactor (WIP)
kriswest May 19, 2025
dd82bb9
feat(key on repo url): consolidate validation for repo creation to re…
kriswest May 19, 2025
a4389b5
feat(key on repo url): add fallback to non-url repo matching
StingRayZA May 20, 2025
3f0b590
feat(key on repo url): switch repo detail used in queries from name t…
kriswest May 20, 2025
db5049e
feat(key on repo url): refactor tests to use repo URLs rather than na…
kriswest May 20, 2025
75ba7b2
feat(key on repo url): switch repo indexing to url field and make uni…
kriswest May 20, 2025
05d35f0
feat(key on repo url): allow file db to delete multiple records
StingRayZA May 20, 2025
f4351e8
feat(key on repo url): switching to key on _id for in API + consolida…
kriswest May 20, 2025
a8a9581
feat(key on repo url): update calls in cli tests to use repo ids
StingRayZA May 21, 2025
ced672d
feat(key on repo url): apply proper typing to DB classes
kriswest May 22, 2025
2e89984
feat(key on repo url): refactoring proxy to support embedding host wi…
kriswest May 28, 2025
5450760
feat(key on repo url): remove defunct config variable
kriswest May 29, 2025
b877f1f
feat(key on repo url): remove unneeded backwards compat in DB
kriswest May 29, 2025
a61cfca
feat(key on repo url): resolving issues in refactored proxy based on …
kriswest May 29, 2025
4cc6a0a
feat(key on repo url): refactor UI to use repo Ids, updated urls and …
kriswest May 29, 2025
4c82cb4
feat(key on repo url): fix issues in CLI tests related to change of k…
kriswest May 30, 2025
52dd897
feat(key on repo url): fix CLI and cypress tests after change to prox…
kriswest Jun 3, 2025
f1f1b9a
chore(key on repo url): clean-up unused helper function and test
kriswest Jun 3, 2025
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
6 changes: 5 additions & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"description": "Configuration for customizing git-proxy",
"type": "object",
"properties": {
"proxyUrl": { "type": "string" },
"proxyUrl": {
"type": "string",
"description": "Used in early versions of git proxy to configure the remote host that traffic is proxied to. In later versions, the repository URL is used to determine the domain proxied, allowing multiple hosts to be proxied by one instance.",
"deprecated": true
},
"cookieSecret": { "type": "string" },
"sessionMaxAgeHours": { "type": "number" },
"api": {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/repo.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Repo', () => {

describe('Code button for repo row', () => {
it('Opens tooltip with correct content and can copy', () => {
const cloneURL = 'http://localhost:8000/finos/test-repo.git';
const cloneURL = 'http://localhost:8000/github.com/finos/test-repo.git';
const tooltipQuery = 'div[role="tooltip"]';

cy
Expand Down
47 changes: 31 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"prepare": "node ./scripts/prepare.js",
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx,json}\" \"test/**/*.{js,jsx,ts,tsx,json}\"",
"lint:fix": "eslint --fix \"src/**/*.{js,jsx,ts,tsx,json}\" \"test/**/*.{js,jsx,ts,tsx,json}\"",
"format": "prettier --write src/**/*.{js,jsx,ts,tsx,css,md,json,scss} test/**/*.{js,jsx,ts,tsx,json} --config ./.prettierrc",
"format": "prettier --write src/**/*.{js,jsx,ts,tsx,css,md,json,scss} test/**/*.{js,jsx,ts,tsx,json} packages/git-proxy-cli/test/**/*.{js,jsx,ts,tsx,json} packages/git-proxy-cli/index.js --config ./.prettierrc",
"gen-schema-doc": "node ./scripts/doc-schema.js",
"cypress:run": "cypress run"
},
Expand Down
7 changes: 3 additions & 4 deletions packages/git-proxy-cli/test/testCli.proxy.config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"tempPassword": {
"sendEmail": false,
"emailConfig": {
}
"emailConfig": {}
},
"authorisedList": [
{
Expand All @@ -22,9 +21,9 @@
{
"type": "mongo",
"connectionString": "mongodb://localhost:27017/gitproxy",
"options": {
"options": {
"useUnifiedTopology": true
},
},
"enabled": false
}
],
Expand Down
14 changes: 7 additions & 7 deletions packages/git-proxy-cli/test/testCli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ describe('test git-proxy-cli', function () {

before(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addGitPushToDb(pushId, TEST_REPO);
await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url);
});

after(async function () {
await helper.removeGitPushFromDb(pushId);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.url);
});

it('attempt to authorise should fail when server is down', async function () {
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('test git-proxy-cli', function () {

after(async function () {
await helper.removeGitPushFromDb(pushId);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.url);
});

it('attempt to cancel should fail when server is down', async function () {
Expand Down Expand Up @@ -415,12 +415,12 @@ describe('test git-proxy-cli', function () {

before(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addGitPushToDb(pushId, TEST_REPO);
await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url);
});

after(async function () {
await helper.removeGitPushFromDb(pushId);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.url);
});

it('attempt to reject should fail when server is down', async function () {
Expand Down Expand Up @@ -492,13 +492,13 @@ describe('test git-proxy-cli', function () {
before(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addUserToDb('testuser1', 'testpassword', 'test@email.com', gitAccount);
await helper.addGitPushToDb(pushId, TEST_REPO, gitAccount);
await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url, gitAccount);
});

after(async function () {
await helper.removeUserFromDb('testuser1');
await helper.removeGitPushFromDb(pushId);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.url);
});

it('attempt to ls should list existing push', async function () {
Expand Down
20 changes: 11 additions & 9 deletions packages/git-proxy-cli/test/testCliUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function runCli(
expectedExitCode = 0,
expectedMessages = null,
expectedErrorMessages = null,
debug = false,
debug = true,
) {
try {
console.log(`cli: '${cli}'`);
Expand Down Expand Up @@ -152,8 +152,9 @@ async function addRepoToDb(newRepo, debug = false) {
const found = repos.find((y) => y.project === newRepo.project && newRepo.name === y.name);
if (!found) {
await db.createRepo(newRepo);
await db.addUserCanPush(newRepo.name, 'admin');
await db.addUserCanAuthorise(newRepo.name, 'admin');
const repo = await db.getRepoByUrl(newRepo.url);
await db.addUserCanPush(repo._id, 'admin');
await db.addUserCanAuthorise(repo._id, 'admin');
if (debug) {
console.log(`New repo added to database: ${newRepo}`);
}
Expand All @@ -166,26 +167,27 @@ async function addRepoToDb(newRepo, debug = false) {

/**
* Removes a repo from the DB.
* @param {string} repoName The name of the repo to remove.
* @param {string} repoUrl The url of the repo to remove.
*/
async function removeRepoFromDb(repoName) {
await db.deleteRepo(repoName);
async function removeRepoFromDb(repoUrl) {
const repo = await db.getRepoByUrl(repoUrl);
await db.deleteRepo(repo._id);
}

/**
* Add a new git push record to the database.
* @param {string} id The ID of the git push.
* @param {string} repo The repository of the git push.
* @param {string} repoUrl The repository URL of the git push.
* @param {string} user The user who pushed the git push.
* @param {boolean} debug Flag to enable logging for debugging.
*/
async function addGitPushToDb(id, repo, user = null, debug = false) {
async function addGitPushToDb(id, repoUrl, user = null, debug = false) {
const action = new actions.Action(
id,
'push', // type
'get', // method
Date.now(), // timestamp
repo,
repoUrl,
);
action.user = user;
const step = new steps.Step(
Expand Down
1 change: 0 additions & 1 deletion proxy.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"proxyUrl": "https://github.com",
"cookieSecret": "cookie secret",
"sessionMaxAgeHours": 12,
"rateLimit": {
Expand Down
4 changes: 2 additions & 2 deletions src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const {
GIT_PROXY_SERVER_PORT = 8000,
GIT_PROXY_HTTPS_SERVER_PORT = 8443,
GIT_PROXY_UI_HOST = 'http://localhost',
GIT_PROXY_UI_PORT = 8080
GIT_PROXY_UI_PORT = 8080,
} = process.env;

export const serverConfig: ServerConfig = {
GIT_PROXY_SERVER_PORT,
GIT_PROXY_HTTPS_SERVER_PORT,
GIT_PROXY_UI_HOST,
GIT_PROXY_UI_PORT
GIT_PROXY_UI_PORT,
};
20 changes: 5 additions & 15 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
let _authentication: Authentication[] = defaultSettings.authentication;
let _apiAuthentication: Authentication[] = defaultSettings.apiAuthentication;
let _tempPassword: TempPasswordConfig = defaultSettings.tempPassword;
let _proxyUrl = defaultSettings.proxyUrl;
let _api: Record<string, unknown> = defaultSettings.api;
let _cookieSecret: string = defaultSettings.cookieSecret;
let _sessionMaxAgeHours: number = defaultSettings.sessionMaxAgeHours;
Expand All @@ -47,15 +46,6 @@
// Create config loader instance
const configLoader = new ConfigLoader(_config);

// Get configured proxy URL
export const getProxyUrl = () => {
if (_userSettings !== null && _userSettings.proxyUrl) {
_proxyUrl = _userSettings.proxyUrl;
}

return _proxyUrl;
};

// Gets a list of authorised repositories
export const getAuthorisedList = () => {
if (_userSettings !== null && _userSettings.authorisedList) {
Expand Down Expand Up @@ -87,12 +77,12 @@
}
}

throw Error('No database cofigured!');
throw Error('No database configured!');

Check warning on line 80 in src/config/index.ts

View check run for this annotation

Codecov / codecov/patch

src/config/index.ts#L80

Added line #L80 was not covered by tests
};

/**
* Get the list of enabled authentication methods
*
*
* At least one authentication method must be enabled.
* @return {Array} List of enabled authentication methods
*/
Expand All @@ -104,15 +94,15 @@
const enabledAuthMethods = _authentication.filter((auth) => auth.enabled);

if (enabledAuthMethods.length === 0) {
throw new Error("No authentication method enabled");
throw new Error('No authentication method enabled');
}

return enabledAuthMethods;
};

/**
* Get the list of enabled authentication methods for API endpoints
*
*
* If no API authentication methods are enabled, all endpoints are public.
* @return {Array} List of enabled authentication methods
*/
Expand All @@ -121,7 +111,7 @@
_apiAuthentication = _userSettings.apiAuthentication;
}

const enabledAuthMethods = _apiAuthentication.filter(auth => auth.enabled);
const enabledAuthMethods = _apiAuthentication.filter((auth) => auth.enabled);

return enabledAuthMethods;
};
Expand Down
16 changes: 3 additions & 13 deletions src/db/file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,19 @@ import * as users from './users';
import * as repo from './repo';
import * as pushes from './pushes';

export const {
getPushes,
writeAudit,
getPush,
deletePush,
authorise,
cancel,
reject,
canUserCancelPush,
canUserApproveRejectPush,
} = pushes;
export const { getPushes, writeAudit, getPush, deletePush, authorise, cancel, reject } = pushes;

export const {
getRepos,
getRepo,
getRepoByUrl,
getRepoById,
createRepo,
addUserCanPush,
addUserCanAuthorise,
removeUserCanPush,
removeUserCanAuthorise,
deleteRepo,
isUserPushAllowed,
canUserApproveRejectPushRepo,
} = repo;

export const { findUser, findUserByOIDC, getUsers, createUser, deleteUser, updateUser } = users;
Loading
Loading