Skip to content

Commit

Permalink
Merge branch 'finos:main' into CheckFilesData
Browse files Browse the repository at this point in the history
  • Loading branch information
Psingle20 authored Nov 11, 2024
2 parents fd26523 + 1e35b93 commit d2314ac
Show file tree
Hide file tree
Showing 23 changed files with 257 additions and 96 deletions.
1 change: 0 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
VITE_API_URI=http://localhost:8080
VITE_SERVER_URI=http://localhost:8000
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
mongodb-version: [4.4]

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
node-version: ${{ env.NODE_VERSION }}

- name: Code Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
egress-policy: audit

- name: "Checkout code"
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

Expand All @@ -64,7 +64,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: SARIF file
path: results.sarif
Expand Down
4 changes: 4 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"description": "Customisable questions to add to attestation form",
"type": "object"
},
"domains": {
"description": "Provide domains to use alternative to the defaults",
"type": "object"
},
"privateOrganizations": {
"description": "Pattern searches for listed private organizations are disabled",
"type": "array"
Expand Down
55 changes: 55 additions & 0 deletions cypress/e2e/repo.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
describe('Repo', () => {
beforeEach(() => {
cy.visit('/admin/repo');

// prevent failures on 404 request and uncaught promises
cy.on('uncaught:exception', () => false);
});

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 tooltipQuery = 'div[role="tooltip"]';

cy
// tooltip isn't open to start with
.get(tooltipQuery)
.should('not.exist');

cy
// find the entry for finos/test-repo
.get('a[href="/admin/repo/test-repo"]')
// take it's parent row
.closest('tr')
// find the nearby span containing Code we can click to open the tooltip
.find('span')
.contains('Code')
.should('exist')
.click();

cy
// find the newly opened tooltip
.get(tooltipQuery)
.should('exist')
.find('span')
// check it contains the url we expect
.contains(cloneURL)
.should('exist')
.parent()
// find the adjacent span that contains the svg
.find('span')
.next()
// check it has the copy icon first and click it
.get('svg.octicon-copy')
.should('exist')
.click()
// check the icon has changed to the check icon
.get('svg.octicon-copy')
.should('not.exist')
.get('svg.octicon-check')
.should('exist');

// failed to successfully check the clipboard
});
});
});
14 changes: 13 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

// start of a login command with sessions
// TODO: resolve issues with the CSRF token
Cypress.Commands.add('login', (username, password) => {
cy.session([username, password], () => {
cy.visit('/login');
cy.get('[data-test=username]').type(username);
cy.get('[data-test=password]').type(password);
cy.get('[data-test=login]').click();
cy.url().should('contain', '/admin/profile');
});
});
41 changes: 27 additions & 14 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@finos/git-proxy",
"version": "1.4.0",
"version": "1.5.1",
"description": "Deploy custom push protections and policies on top of Git.",
"scripts": {
"cli": "node ./packages/git-proxy-cli/index.js",
"client": "vite --config vite.config.js",
"clientinstall": "npm install --prefix client",
"server": "node index.js",
"start": "concurrently 'npm run server' 'npm run client'",
"start": "concurrently \"npm run server\" \"npm run client\"",
"build": "vite build",
"test": "NODE_ENV=test mocha --exit",
"test-coverage": "nyc npm run test",
Expand Down
1 change: 1 addition & 0 deletions proxy.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
}
]
},
"domains": {},
"privateOrganizations": [],
"urlShortener": "",
"contactEmail": "",
Expand Down
1 change: 1 addition & 0 deletions scripts/doc-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ try {
console.log(genDocOutput);

const schemaDoc = readFileSync(`${tempdir}${sep}schema.md`, 'utf-8')
.replace(/\s\s\n\n<\/summary>/g, '\n</summary>')
.replace(/# GitProxy configuration file/g, '# Schema Reference'); // https://github.com/finos/git-proxy/pull/327#discussion_r1377343213
const docString = `---
title: Schema Reference
Expand Down
9 changes: 9 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let _privateOrganizations = defaultSettings.privateOrganizations;
let _urlShortener = defaultSettings.urlShortener;
let _contactEmail = defaultSettings.contactEmail;
let _csrfProtection = defaultSettings.csrfProtection;
let _domains = defaultSettings.domains;

// Get configured proxy URL
const getProxyUrl = () => {
Expand Down Expand Up @@ -189,6 +190,13 @@ const getSSLCertPath = () => {
return _sslCertPath;
};

const getDomains = () => {
if (_userSettings && _userSettings.domains) {
_domains = _userSettings.domains;
}
return _domains;
};

exports.getAPIs = getAPIs;
exports.getProxyUrl = getProxyUrl;
exports.getAuthorisedList = getAuthorisedList;
Expand All @@ -207,3 +215,4 @@ exports.getCSRFProtection = getCSRFProtection;
exports.getPlugins = getPlugins;
exports.getSSLKeyPath = getSSLKeyPath;
exports.getSSLCertPath = getSSLCertPath;
exports.getDomains = getDomains;
7 changes: 4 additions & 3 deletions src/proxy/processors/push-action/blockForAuth.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const Step = require('../../actions').Step;
const { getServiceUIURL } = require('../../../service/urls');

const { GIT_PROXY_UI_PORT: uiPort } = require('../../../config/env').Vars;
const Step = require('../../actions').Step;

const exec = async (req, action) => {
const step = new Step('authBlock');
const url = getServiceUIURL(req);

const message =
'\n\n\n' +
`\x1B[32mGitProxy has received your push ✅\x1B[0m\n\n` +
'🔗 Shareable Link\n\n' +
`\x1B[34mhttp://localhost:${uiPort}/admin/push/${action.id}\x1B[0m` +
`\x1B[34m${url}/admin/push/${action.id}\x1B[0m` +
'\n\n\n';
step.setAsyncBlock(message);

Expand Down
2 changes: 1 addition & 1 deletion src/proxy/processors/push-action/pullRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const exec = async (req, action) => {
}

if (!fs.existsSync(action.proxyGitPath)) {
fs.mkdirSync(action.proxyGitPath, '0777', true);
fs.mkdirSync(action.proxyGitPath, '0755', true);
}

const cmd = `git clone ${action.url} --bare`;
Expand Down
9 changes: 7 additions & 2 deletions src/service/routes/repo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const express = require('express');
const router = new express.Router();
const db = require('../../db');
const { getProxyURL } = require('../urls');

router.get('/', async (req, res) => {
const proxyURL = getProxyURL(req);
const query = {
type: 'push',
};
Expand All @@ -18,12 +20,15 @@ router.get('/', async (req, res) => {
query[k] = v;
}

res.send(await db.getRepos(query));
const qd = await db.getRepos(query);
res.send(qd.map((d) => ({ ...d, proxyURL })));
});

router.get('/:name', async (req, res) => {
const proxyURL = getProxyURL(req);
const name = req.params.name;
res.send(await db.getRepo(name));
const qd = await db.getRepo(name);
res.send({ ...qd, proxyURL });
});

router.patch('/:name/user/push', async (req, res) => {
Expand Down
20 changes: 20 additions & 0 deletions src/service/urls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { GIT_PROXY_SERVER_PORT: PROXY_HTTP_PORT, GIT_PROXY_UI_PORT: UI_PORT } =
require('../config/env').Vars;
const config = require('../config');

module.exports = {
getProxyURL: (req) => {
const defaultURL = `${req.protocol}://${req.headers.host}`.replace(
`:${UI_PORT}`,
`:${PROXY_HTTP_PORT}`,
);
return config.getDomains().proxy ?? defaultURL;
},
getServiceUIURL: (req) => {
const defaultURL = `${req.protocol}://${req.headers.host}`.replace(
`:${PROXY_HTTP_PORT}`,
`:${UI_PORT}`,
);
return config.getDomains().service ?? defaultURL;
},
};
4 changes: 2 additions & 2 deletions src/ui/views/RepoDetails/RepoDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export default function RepoDetails() {
if (isLoading) return <div>Loading...</div>;
if (isError) return <div>Something went wrong ...</div>;

const { project: org, name } = data || {};
const cloneURL = `${import.meta.env.VITE_SERVER_URI}/${org}/${name}.git`;
const { project: org, name, proxyURL } = data || {};
const cloneURL = `${proxyURL}/${org}/${name}.git`;

return (
<GridContainer>
Expand Down
4 changes: 2 additions & 2 deletions src/ui/views/RepoList/Components/RepoOverview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ export default function Repositories(props) {
});
};

const { project: org, name } = props?.data || {};
const cloneURL = `${window.location.origin.toString()}/${org}/${name}.git`;
const { project: org, name, proxyURL } = props?.data || {};
const cloneURL = `${proxyURL}/${org}/${name}.git`;

return (
<TableRow>
Expand Down
Loading

0 comments on commit d2314ac

Please sign in to comment.