Skip to content

Commit b378b8c

Browse files
authored
Fix regression on login path when using redirect url (#3038)
1 parent 2c42d7f commit b378b8c

File tree

6 files changed

+129
-2
lines changed

6 files changed

+129
-2
lines changed

.github/workflows/jobs.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,55 @@ jobs:
200200
run: |
201201
make console
202202
203+
test-nginx-subpath:
204+
name: Test Subpath with Nginx
205+
needs:
206+
- compile-binary
207+
runs-on: [ubuntu-latest]
208+
timeout-minutes: 10
209+
strategy:
210+
matrix:
211+
go-version: [1.21.x]
212+
os: [ubuntu-latest]
213+
steps:
214+
- name: Check out code
215+
uses: actions/checkout@v3
216+
- uses: actions/setup-node@v3
217+
with:
218+
node-version: ${{ env.NVMRC }}
219+
- name: Install MinIO JS
220+
working-directory: ./
221+
continue-on-error: false
222+
run: |
223+
yarn add minio
224+
225+
- uses: actions/cache@v3
226+
name: Console Binary Cache
227+
with:
228+
path: |
229+
./console
230+
key: ${{ runner.os }}-binary-${{ github.run_id }}
231+
232+
- name: clean-previous-containers-if-any
233+
run: |
234+
docker stop minio || true;
235+
docker container prune -f || true;
236+
237+
- name: Start Console, MinIO and Nginx
238+
run: |
239+
(CONSOLE_SUBPATH=/console/subpath ./console server ) & (make test-initialize-minio-nginx)
240+
241+
- name: Install TestCafe
242+
run: npm install testcafe@3.0.0
243+
244+
- name: Run TestCafe Tests
245+
run: npx testcafe "chrome:headless" portal-ui/tests/subpath-nginx/ -q --skip-js-errors -c 3
246+
247+
- name: Clean up docker
248+
if: always()
249+
run: |
250+
make cleanup-minio-nginx
251+
203252
all-permissions-1:
204253
name: Permissions Tests Part 1
205254
needs:

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,30 @@ cleanup-permissions:
229229
@(env bash $(PWD)/portal-ui/tests/scripts/cleanup-env.sh)
230230
@(docker stop minio)
231231

232+
initialize-docker-network:
233+
@(docker network create test-network)
234+
235+
test-start-docker-minio-w-redirect-url: initialize-docker-network
236+
@(docker run \
237+
-e MINIO_BROWSER_REDIRECT_URL='http://localhost:8000/console/subpath/' \
238+
-e MINIO_SERVER_URL='http://localhost:9000' \
239+
-v /data1 -v /data2 -v /data3 -v /data4 \
240+
-d --network host --name minio --rm\
241+
quay.io/minio/minio:latest server /data{1...4})
242+
243+
test-start-docker-nginx-w-subpath:
244+
@(docker run \
245+
--network host \
246+
-d --rm \
247+
--add-host=host.docker.internal:host-gateway \
248+
-v ./portal-ui/tests/subpath-nginx/nginx.conf:/etc/nginx/nginx.conf \
249+
--name test-nginx nginx)
250+
251+
test-initialize-minio-nginx: test-start-docker-minio-w-redirect-url test-start-docker-nginx-w-subpath
252+
253+
cleanup-minio-nginx:
254+
@(docker stop minio test-nginx & docker network rm test-network)
255+
232256
test:
233257
@echo "execute test and get coverage"
234258
@(cd restapi && mkdir coverage && GO111MODULE=on go test -test.v -coverprofile=coverage/coverage.out)

portal-ui/src/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ api.request = async <T = any, E = any>({
2525
cancelToken,
2626
...params,
2727
});
28-
return internalResp.catch((e) => CommonAPIValidation(e));
28+
return internalResp.then((e) => CommonAPIValidation(e));
2929
};
3030

3131
export function CommonAPIValidation<D, E>(
@@ -37,5 +37,5 @@ export function CommonAPIValidation<D, E>(
3737
document.location = "/login";
3838
}
3939
}
40-
throw res;
40+
return res;
4141
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
events { worker_connections 1024; }
2+
http {
3+
server {
4+
listen 8000;
5+
location /console/subpath/ {
6+
rewrite ^/console/subpath/(.*) /$1 break;
7+
proxy_pass http://host.docker.internal:9090;
8+
9+
proxy_http_version 1.1;
10+
proxy_set_header Upgrade $http_upgrade;
11+
proxy_set_header Connection "Upgrade";
12+
proxy_set_header Host $host;
13+
proxy_set_header X-Real-IP $remote_addr;
14+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15+
proxy_set_header X-Forwarded-Proto $scheme;
16+
17+
# This allows WebSocket connections
18+
proxy_set_header Upgrade $http_upgrade;
19+
proxy_set_header Connection "upgrade";
20+
}
21+
}
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2023 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import * as elements from "../utils/elements";
18+
19+
// Using subpath defined in `MINIO_BROWSER_REDIRECT_URL`
20+
const appBaseUrl = "http://localhost:8000/console/subpath";
21+
let rootUrl = `${appBaseUrl}/`;
22+
23+
fixture("Tests using subpath").page(appBaseUrl);
24+
25+
test("RootUrl redirects to Login Page", async (t) => {
26+
const loginButtonExists = elements.loginButton.exists;
27+
await t.navigateTo(rootUrl).expect(loginButtonExists).ok().wait(2000);
28+
});

portal-ui/tests/utils/elements.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,7 @@ export const locationEmpty = Selector("div").withAttribute(
191191
"id",
192192
"empty-results",
193193
);
194+
//----------------------------------------------------
195+
// Login Window
196+
//----------------------------------------------------
197+
export const loginButton = Selector("button").withAttribute("id", "do-login");

0 commit comments

Comments
 (0)