Skip to content

Commit e7f474f

Browse files
authored
Merge branch 'main' into fix/slack-url
2 parents 4d95b9c + 4e77a0f commit e7f474f

File tree

36 files changed

+408
-86
lines changed

36 files changed

+408
-86
lines changed

config.schema.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@
124124
"description": "Configuration source"
125125
}
126126
}
127+
},
128+
"uiRouteAuth": {
129+
"description": "UI routes that require authentication (logged in or admin)",
130+
"type": "object",
131+
"properties": {
132+
"enabled": { "type": "boolean" },
133+
"rules": {
134+
"type": "array",
135+
"items": {
136+
"$ref": "#/definitions/routeAuthRule"
137+
}
138+
}
139+
}
127140
}
128141
},
129142
"definitions": {
@@ -155,6 +168,14 @@
155168
"options": { "type": "object" }
156169
},
157170
"required": ["type", "enabled"]
171+
},
172+
"routeAuthRule": {
173+
"type": "object",
174+
"properties": {
175+
"pattern": { "type": "string" },
176+
"adminOnly": { "type": "boolean" },
177+
"loginRequired": { "type": "boolean" }
178+
}
158179
}
159180
},
160181
"additionalProperties": false

cypress/e2e/autoApproved.cy.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import moment from 'moment';
22

33
describe('Auto-Approved Push Test', () => {
44
beforeEach(() => {
5+
cy.login('admin', 'admin');
6+
57
cy.intercept('GET', '/api/v1/push/123', {
68
statusCode: 200,
79
body: {
@@ -45,7 +47,7 @@ describe('Auto-Approved Push Test', () => {
4547
});
4648

4749
it('should display auto-approved message and verify tooltip contains the expected timestamp', () => {
48-
cy.visit('/admin/push/123');
50+
cy.visit('/dashboard/push/123');
4951

5052
cy.wait('@getPush');
5153

cypress/e2e/login.cy.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ describe('Login page', () => {
1919
cy.get('[data-test="login"]').should('exist');
2020
});
2121

22+
it('should redirect to repo list on valid login', () => {
23+
cy.intercept('GET', '**/api/auth/me').as('getUser');
24+
25+
cy.get('[data-test="username"]').type('admin');
26+
cy.get('[data-test="password"]').type('admin');
27+
cy.get('[data-test="login"]').click();
28+
29+
cy.wait('@getUser');
30+
31+
cy.url().should('include', '/dashboard/repo');
32+
})
33+
2234
describe('OIDC login button', () => {
2335
it('should exist', () => {
2436
cy.get('[data-test="oidc-login"]').should('exist');

cypress/e2e/repo.cy.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
describe('Repo', () => {
22
beforeEach(() => {
3-
cy.visit('/admin/repo');
3+
cy.login('admin', 'admin');
4+
5+
cy.visit('/dashboard/repo');
46

57
// prevent failures on 404 request and uncaught promises
68
cy.on('uncaught:exception', () => false);
@@ -18,7 +20,7 @@ describe('Repo', () => {
1820

1921
cy
2022
// find the entry for finos/test-repo
21-
.get('a[href="/admin/repo/test-repo"]')
23+
.get('a[href="/dashboard/repo/test-repo"]')
2224
// take it's parent row
2325
.closest('tr')
2426
// find the nearby span containing Code we can click to open the tooltip

cypress/support/commands.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@
2929
Cypress.Commands.add('login', (username, password) => {
3030
cy.session([username, password], () => {
3131
cy.visit('/login');
32+
cy.intercept('GET', '**/api/auth/me').as('getUser');
33+
3234
cy.get('[data-test=username]').type(username);
3335
cy.get('[data-test=password]').type(password);
3436
cy.get('[data-test=login]').click();
35-
cy.url().should('contain', '/admin/profile');
37+
38+
cy.wait('@getUser');
39+
cy.url().should('include', '/dashboard/repo');
3640
});
3741
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@finos/git-proxy",
3-
"version": "1.14.0",
3+
"version": "1.15.0",
44
"description": "Deploy custom push protections and policies on top of Git.",
55
"scripts": {
66
"cli": "node ./packages/git-proxy-cli/index.js",

proxy.config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,20 @@
139139
"enabled": false,
140140
"key": "certs/key.pem",
141141
"cert": "certs/cert.pem"
142+
},
143+
"uiRouteAuth": {
144+
"enabled": false,
145+
"rules": [
146+
{
147+
"pattern": "/dashboard/*",
148+
"adminOnly": false,
149+
"loginRequired": true
150+
},
151+
{
152+
"pattern": "/admin/*",
153+
"adminOnly": true,
154+
"loginRequired": true
155+
}
156+
]
142157
}
143158
}

src/config/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ let _rateLimit: RateLimitConfig = defaultSettings.rateLimit;
3838
let _tlsEnabled = defaultSettings.tls.enabled;
3939
let _tlsKeyPemPath = defaultSettings.tls.key;
4040
let _tlsCertPemPath = defaultSettings.tls.cert;
41+
let _uiRouteAuth: Record<string, unknown> = defaultSettings.uiRouteAuth;
4142

4243
// Initialize configuration with defaults and user settings
4344
let _config = { ...defaultSettings, ...(_userSettings || {}) } as Configuration;
@@ -229,6 +230,13 @@ export const getDomains = () => {
229230
return _domains;
230231
};
231232

233+
export const getUIRouteAuth = () => {
234+
if (_userSettings && _userSettings.uiRouteAuth) {
235+
_uiRouteAuth = _userSettings.uiRouteAuth;
236+
}
237+
return _uiRouteAuth;
238+
};
239+
232240
export const getRateLimit = () => {
233241
if (_userSettings && _userSettings.rateLimit) {
234242
_rateLimit = _userSettings.rateLimit;

src/index.jsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import { createBrowserHistory } from 'history';
44
import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom';
5+
import { AuthProvider } from './ui/auth/AuthProvider';
56

67
// core components
7-
import Admin from './ui/layouts/Admin';
8+
import Dashboard from './ui/layouts/Dashboard';
89
import Login from './ui/views/Login/Login';
910
import './ui/assets/css/material-dashboard-react.css';
11+
import NotAuthorized from './ui/views/Extras/NotAuthorized';
12+
import NotFound from './ui/views/Extras/NotFound';
1013

1114
const hist = createBrowserHistory();
1215

1316
ReactDOM.render(
14-
<Router history={hist}>
15-
<Routes>
16-
<Route exact path='/admin/*' element={<Admin />} />
17-
<Route exact path='/login' element={<Login />} />
18-
<Route exact path='/' element={<Navigate from='/' to='/admin/repo' />} />
19-
</Routes>
20-
</Router>,
17+
<AuthProvider>
18+
<Router history={hist}>
19+
<Routes>
20+
<Route exact path='/dashboard/*' element={<Dashboard />} />
21+
<Route exact path='/login' element={<Login />} />
22+
<Route exact path='/not-authorized' element={<NotAuthorized />} />
23+
<Route exact path='/' element={<Navigate from='/' to='/dashboard/repo' />} />
24+
<Route path='*' element={<NotFound />} />
25+
</Routes>
26+
</Router>
27+
</AuthProvider>,
2128
document.getElementById('root'),
2229
);

0 commit comments

Comments
 (0)