Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4ef686f
fix: remove incorrect default query from repos page (that is ignored …
kriswest Mar 21, 2025
232c466
fix: passthrough repository queries
kriswest Mar 25, 2025
ab362e4
test: use unique emails for users in tests and remove afterwards
kriswest Apr 1, 2025
2e3282d
Merge remote-tracking branch 'upstream/main' into 947-repository-list…
kriswest Apr 11, 2025
12e7bfe
test: don't clean-up test-repo as cypress tests rely on it
kriswest Apr 11, 2025
200788c
fix: add indexes, compaction and consistent lowercasing of inputs in …
kriswest Mar 25, 2025
9769be6
fix: consistent lowercasing of inputs in mongoDB implementation
kriswest Mar 25, 2025
188d820
fix: make repo name index non-unique (currently assumed unique but wo…
kriswest Mar 25, 2025
f38c266
test: use unique emails for users in tests and remove afterwards
kriswest Apr 1, 2025
4632e86
fix: add indexes, compaction and consistent lowercasing of inputs in …
kriswest Mar 25, 2025
40a83b5
chore: porting changes from users.js
kriswest Apr 8, 2025
6f08207
fix: bad merge
kriswest Apr 10, 2025
092ec13
test: don't clean-up test-repo as cypress tests rely on it
kriswest Apr 11, 2025
08a6c82
fix: add indexes, compaction and consistent lowercasing of inputs in …
kriswest Mar 25, 2025
1966088
test: use unique emails for users in tests and remove afterwards
kriswest Apr 1, 2025
8463c71
fix: add indexes, compaction and consistent lowercasing of inputs in …
kriswest Mar 25, 2025
fa5f270
fix: consistent lowercasing of inputs in mongoDB implementation
kriswest Mar 25, 2025
4abbe28
chore: porting changes from users.js
kriswest Apr 8, 2025
8a73e5a
fix: bad merge
kriswest Apr 10, 2025
7aaf03c
test: don't clean-up test-repo as cypress tests rely on it
kriswest Apr 11, 2025
5db446b
Merge branch '947-repository-listing-fixes' into 948-neDB-implementat…
kriswest Apr 11, 2025
008e4fa
test: basic db test coverage
kriswest Apr 15, 2025
fa234f8
fix: clean-up DB after CLI tests
kriswest Apr 11, 2025
b67a81c
Merge branch '948-neDB-implementation-issues' of https://natwest.gitl…
kriswest Apr 15, 2025
734fc30
test: more DB test coverage
kriswest Apr 15, 2025
4ff22a3
test: more code coverage in DB and service/routes/repo
kriswest Apr 16, 2025
520a9bc
Merge branch 'main' into 948-neDB-implementation-issues
kriswest Apr 16, 2025
79a30ba
Merge remote-tracking branch 'upstream/948-neDB-implementation-issues…
kriswest Apr 16, 2025
fe64a91
test: more DB test coverage
kriswest Apr 17, 2025
ec4516a
Merge branch 'main' into 948-neDB-implementation-issues
JamieSlome May 6, 2025
ddcc149
Merge branch 'main' into 948-neDB-implementation-issues
kriswest May 7, 2025
b5cd038
chore: extended prettier format command to package/git-proxy-cli and …
kriswest May 7, 2025
12f20c9
Merge branch 'main' into 948-neDB-implementation-issues
kriswest May 19, 2025
c49ae45
Merge branch 'main' into 948-neDB-implementation-issues
JamieSlome May 20, 2025
b434e43
Merge branch 'main' into 948-neDB-implementation-issues
kriswest May 28, 2025
fe3b5a0
Merge branch 'main' into 948-neDB-implementation-issues
kriswest May 30, 2025
37f1684
Merge remote-tracking branch 'github/948-neDB-implementation-issues' …
kriswest May 30, 2025
13aa96e
Merge branch 'main' into 948-neDB-implementation-issues
kriswest Jun 3, 2025
b10763f
Merge branch 'main' into 948-neDB-implementation-issues
JamieSlome Jun 4, 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
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
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,
};
21 changes: 18 additions & 3 deletions src/db/file/pushes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import { toClass } from '../helper';
import * as repo from './repo';
import { PushQuery } from '../types';

const COMPACTION_INTERVAL = 1000 * 60 * 60 * 24; // once per day

// these don't get coverage in tests as they have already been run once before the test
/* istanbul ignore if */
if (!fs.existsSync('./.data')) fs.mkdirSync('./.data');
/* istanbul ignore if */
if (!fs.existsSync('./.data/db')) fs.mkdirSync('./.data/db');

const db = new Datastore({ filename: './.data/db/pushes.db', autoload: true });
db.ensureIndex({ fieldName: 'id', unique: true });
db.setAutocompactionInterval(COMPACTION_INTERVAL);

const defaultPushQuery: PushQuery = {
error: false,
Expand All @@ -22,6 +29,8 @@ export const getPushes = (query: PushQuery) => {
if (!query) query = defaultPushQuery;
return new Promise((resolve, reject) => {
db.find(query, (err: Error, docs: Action[]) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -38,6 +47,8 @@ export const getPushes = (query: PushQuery) => {
export const getPush = async (id: string) => {
return new Promise<Action | null>((resolve, reject) => {
db.findOne({ id: id }, (err, doc) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -54,6 +65,8 @@ export const getPush = async (id: string) => {
export const deletePush = async (id: string) => {
return new Promise<void>((resolve, reject) => {
db.remove({ id }, (err) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -67,6 +80,8 @@ export const writeAudit = async (action: Action) => {
return new Promise((resolve, reject) => {
const options = { multi: false, upsert: true };
db.update({ id: action.id }, action, options, (err) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand Down Expand Up @@ -115,7 +130,7 @@ export const cancel = async (id: string) => {
return { message: `cancel ${id}` };
};

export const canUserCancelPush = async (id: string, user: any) => {
export const canUserCancelPush = async (id: string, user: string) => {
return new Promise<boolean>(async (resolve) => {
const pushDetail = await getPush(id);
if (!pushDetail) {
Expand All @@ -134,14 +149,14 @@ export const canUserCancelPush = async (id: string, user: any) => {
});
};

export const canUserApproveRejectPush = async (id: string, user: any) => {
export const canUserApproveRejectPush = async (id: string, user: string) => {
return new Promise<boolean>(async (resolve) => {
const action = await getPush(id);
if (!action) {
resolve(false);
return;
}
const repoName = action?.repoName.replace('.git', '');
const repoName = action.repoName.replace('.git', '');
const isAllowed = await repo.canUserApproveRejectPushRepo(repoName, user);

resolve(isAllowed);
Expand Down
60 changes: 56 additions & 4 deletions src/db/file/repo.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import fs from 'fs';
import Datastore from '@seald-io/nedb'
import Datastore from '@seald-io/nedb';
import { Repo } from '../types';

const COMPACTION_INTERVAL = 1000 * 60 * 60 * 24; // once per day

// these don't get coverage in tests as they have already been run once before the test
/* istanbul ignore if */
if (!fs.existsSync('./.data')) fs.mkdirSync('./.data');
/* istanbul ignore if */
if (!fs.existsSync('./.data/db')) fs.mkdirSync('./.data/db');

const db = new Datastore({ filename: './.data/db/repos.db', autoload: true });
db.ensureIndex({ fieldName: 'name', unique: false });
db.setAutocompactionInterval(COMPACTION_INTERVAL);

const isBlank = (str: string) => {
return !str || /^\s*$/.test(str);
};

export const getRepos = async (query: any = {}) => {
if (query?.name) {
query.name = query.name.toLowerCase();
}
return new Promise<Repo[]>((resolve, reject) => {
db.find({}, (err: Error, docs: Repo[]) => {
db.find(query, (err: Error, docs: Repo[]) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -21,7 +37,9 @@ export const getRepos = async (query: any = {}) => {

export const getRepo = async (name: string) => {
return new Promise<Repo | null>((resolve, reject) => {
db.findOne({ name }, (err: Error | null, doc: Repo) => {
db.findOne({ name: name.toLowerCase() }, (err: Error | null, doc: Repo) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -31,15 +49,28 @@ export const getRepo = async (name: string) => {
});
};


export const createRepo = async (repo: Repo) => {
if (isBlank(repo.project)) {
throw new Error('Project name cannot be empty');
}
if (isBlank(repo.name)) {
throw new Error('Repository name cannot be empty');
} else {
repo.name = repo.name.toLowerCase();
}
if (isBlank(repo.url)) {
throw new Error('URL cannot be empty');
}

repo.users = {
canPush: [],
canAuthorise: [],
};

return new Promise<Repo>((resolve, reject) => {
db.insert(repo, (err, doc) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -50,6 +81,8 @@ export const createRepo = async (repo: Repo) => {
};

export const addUserCanPush = async (name: string, user: string) => {
name = name.toLowerCase();
user = user.toLowerCase();
return new Promise(async (resolve, reject) => {
const repo = await getRepo(name);
if (!repo) {
Expand All @@ -65,6 +98,8 @@ export const addUserCanPush = async (name: string, user: string) => {

const options = { multi: false, upsert: false };
db.update({ name: name }, repo, options, (err) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -75,6 +110,8 @@ export const addUserCanPush = async (name: string, user: string) => {
};

export const addUserCanAuthorise = async (name: string, user: string) => {
name = name.toLowerCase();
user = user.toLowerCase();
return new Promise(async (resolve, reject) => {
const repo = await getRepo(name);
if (!repo) {
Expand All @@ -91,6 +128,8 @@ export const addUserCanAuthorise = async (name: string, user: string) => {

const options = { multi: false, upsert: false };
db.update({ name: name }, repo, options, (err) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -101,6 +140,8 @@ export const addUserCanAuthorise = async (name: string, user: string) => {
};

export const removeUserCanAuthorise = async (name: string, user: string) => {
name = name.toLowerCase();
user = user.toLowerCase();
return new Promise(async (resolve, reject) => {
const repo = await getRepo(name);
if (!repo) {
Expand All @@ -112,6 +153,8 @@ export const removeUserCanAuthorise = async (name: string, user: string) => {

const options = { multi: false, upsert: false };
db.update({ name: name }, repo, options, (err) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -122,6 +165,8 @@ export const removeUserCanAuthorise = async (name: string, user: string) => {
};

export const removeUserCanPush = async (name: string, user: string) => {
name = name.toLowerCase();
user = user.toLowerCase();
return new Promise(async (resolve, reject) => {
const repo = await getRepo(name);
if (!repo) {
Expand All @@ -133,6 +178,8 @@ export const removeUserCanPush = async (name: string, user: string) => {

const options = { multi: false, upsert: false };
db.update({ name: name }, repo, options, (err) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -143,8 +190,11 @@ export const removeUserCanPush = async (name: string, user: string) => {
};

export const deleteRepo = async (name: string) => {
name = name.toLowerCase();
return new Promise<void>((resolve, reject) => {
db.remove({ name: name }, (err) => {
// ignore for code coverage as neDB rarely returns errors even for an invalid query
/* istanbul ignore if */
if (err) {
reject(err);
} else {
Expand All @@ -156,6 +206,7 @@ export const deleteRepo = async (name: string) => {

export const isUserPushAllowed = async (name: string, user: string) => {
name = name.toLowerCase();
user = user.toLowerCase();
return new Promise<boolean>(async (resolve) => {
const repo = await getRepo(name);
if (!repo) {
Expand All @@ -176,6 +227,7 @@ export const isUserPushAllowed = async (name: string, user: string) => {

export const canUserApproveRejectPushRepo = async (name: string, user: string) => {
name = name.toLowerCase();
user = user.toLowerCase();
console.log(`checking if user ${user} can approve/reject for ${name}`);
return new Promise<boolean>(async (resolve) => {
const repo = await getRepo(name);
Expand Down
Loading
Loading