Skip to content

Commit e4d75ab

Browse files
committed
fix proxy, html5 and selenium issues
1 parent f94a1cd commit e4d75ab

File tree

9 files changed

+194
-97
lines changed

9 files changed

+194
-97
lines changed

.devcontainer/docker-compose.yml

-5
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,3 @@ services:
5555
chmod 600 /tmp/pgpass;
5656
/entrypoint.sh;
5757
"
58-
59-
chrome:
60-
image: seleniarm/standalone-chromium:116.0-chromedriver-116.0-grid-4.10.0-20230828
61-
restart: unless-stopped
62-
shm_size: '2gb'

server/src/main/java/mucsi96/traininglog/strava/StravaConfiguration.java

-5
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ Converter<OAuth2AuthorizationCodeGrantRequest, MultiValueMap<String, String>> st
108108
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
109109
parameters.add(OAuth2ParameterNames.CLIENT_ID, request.getClientRegistration().getClientId());
110110
parameters.add(OAuth2ParameterNames.CLIENT_SECRET, request.getClientRegistration().getClientSecret());
111-
// parameters.add(OAuth2ParameterNames.CODE,
112-
// request.getAuthorizationExchange().getAuthorizationResponse().getCode());
113-
// parameters.add(OAuth2ParameterNames.GRANT_TYPE, "authorization_code");
114111
return parameters;
115112
};
116113
}
@@ -121,8 +118,6 @@ Converter<OAuth2RefreshTokenGrantRequest, MultiValueMap<String, String>> stravaR
121118
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
122119
parameters.add(OAuth2ParameterNames.CLIENT_ID, request.getClientRegistration().getClientId());
123120
parameters.add(OAuth2ParameterNames.CLIENT_SECRET, request.getClientRegistration().getClientSecret());
124-
// parameters.add(OAuth2ParameterNames.GRANT_TYPE, "refresh_token");
125-
// parameters.add(OAuth2ParameterNames.REFRESH_TOKEN, request.getRefreshToken().getTokenValue());
126121
return parameters;
127122
};
128123
}

test/docker-compose.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ const os = require("os");
22
const arch = os.arch();
33
const dockerNetwork = process.env.DOCKER_NETWORK;
44
const workspaceRoot = process.env.WORKSPACE_ROOT ?? "..";
5-
const gatewayPort = 9780;
6-
const gatewayHost = `http://${
7-
dockerNetwork ? "reverse-proxy" : `localhost:${gatewayPort}`
8-
}`;
95

106
const config = {
117
version: "3.8",
@@ -50,12 +46,12 @@ const config = {
5046
SPRING_ACTUATOR_PORT: 8082,
5147
SPRING_ADMIN_SERVER_HOST: "localhost",
5248
SPRING_ADMIN_SERVER_PORT: 9090,
53-
WEBDRIVER_API_URI: `${gatewayHost}/chrome/wd/hub`,
54-
WITHINGS_ACCOUNTS_URI: `${gatewayHost}/withings`,
55-
WITHINGS_API_URI: `${gatewayHost}/withings`,
49+
WEBDRIVER_API_URI: "http://chrome:4444/chrome/wd/hub",
50+
WITHINGS_ACCOUNTS_URI: "http://mock-withings:8080/withings",
51+
WITHINGS_API_URI: "http://mock-withings:8080/withings",
5652
WITHINGS_CLIENT_ID: "withings-client-id",
5753
WITHINGS_CLIENT_SECRET: "withings-client-secret",
58-
STRAVA_API_URI: `${gatewayHost}/strava`,
54+
STRAVA_API_URI: "http://mock-strava:8080/strava",
5955
STRAVA_CLIENT_ID: "strava-client-id",
6056
STRAVA_CLIENT_SECRET: "strava-client-secret",
6157
},
@@ -72,12 +68,17 @@ const config = {
7268
},
7369
},
7470
},
71+
traefik_dynamic_conf: {
72+
build: "./reverse_proxy",
73+
environment: {
74+
DOCKER_NETWORK: process.env.DOCKER_NETWORK,
75+
},
76+
},
7577
"reverse-proxy": {
7678
image: "traefik",
77-
ports: [`${gatewayPort}:80`],
79+
ports: ["9780:80"],
7880
volumes: [
7981
`${workspaceRoot}/test/reverse_proxy/traefik_static_conf.yml:/etc/traefik/traefik.yml`,
80-
`${workspaceRoot}/test/reverse_proxy/traefik_dynamic_conf.yml:/etc/traefik/traefik_dynamic_conf.yml`,
8182
],
8283
},
8384
chrome: {

test/mock_strava/authorize.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ function authozire(request, response) {
1919
location.searchParams.append("code", "authorization-code");
2020

2121
response.writeHead(200, {
22-
'Content-Type': 'text/html;charset=utf-8'
23-
})
24-
return response.end(`
22+
"Content-Type": "text/html;charset=utf-8",
23+
});
24+
const responseBody = `
25+
<!DOCTYPE html>
2526
<h1>Mock Strava</h1>
2627
<a href="${location.toString()}">Authorize</a>
27-
`);
28+
`;
29+
console.log("Response: ", responseBody);
30+
return response.end(responseBody);
2831
}
2932

3033
module.exports = {

test/mock_withings/authorize.js

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function authozire(request, response) {
2222
"Content-Type": "text/html;charset=utf-8",
2323
});
2424
const responseBody = `
25+
<!DOCTYPE html>
2526
<h1>Mock Withings</h1>
2627
<a href="${location.toString()}">Authorize</a>
2728
`;

test/reverse_proxy/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:18
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY . .
6+
7+
EXPOSE 8080
8+
9+
CMD [ "node", "traefik_dynamic_conf.js" ]
+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
const { createServer } = require("http");
2+
const PORT = 8080;
3+
const server = createServer();
4+
5+
const entrypoint = process.env.DOCKER_NETWORKE
6+
? "http://reverse-proxy"
7+
: "http://localhost:9780";
8+
9+
const routers = {
10+
client: {
11+
entryPoints: ["web"],
12+
service: "client",
13+
rule: "PathPrefix(`/`)",
14+
},
15+
servers: {
16+
entryPoints: ["web"],
17+
middlewares: ["authHeaders", "rewriteWithings", "rewriteStrava"],
18+
service: "server",
19+
rule: "PathPrefix(`/api`)",
20+
},
21+
mockBackupTool: {
22+
entryPoints: ["web"],
23+
service: "mockBackupTool",
24+
rule: "Path(`/db/last-backup-time`)",
25+
},
26+
mockWithings: {
27+
entryPoints: ["web"],
28+
service: "mockWithings",
29+
rule: "PathPrefix(`/withings`)",
30+
},
31+
mockStrava: {
32+
entryPoints: ["web"],
33+
service: "mockStrava",
34+
rule: "PathPrefix(`/strava`)",
35+
},
36+
chrome: {
37+
entryPoints: ["web"],
38+
service: "chrome",
39+
rule: "PathPrefix(`/chrome`)",
40+
},
41+
};
42+
43+
const middlewares = {
44+
authHeaders: {
45+
headers: {
46+
customRequestHeaders: {
47+
"Remote-User": "rob",
48+
"Remote-Groups": "user",
49+
"Remote-Name": "Robert White",
50+
"Remote-Email": "[email protected]",
51+
},
52+
},
53+
},
54+
rewriteWithings: {
55+
plugin: {
56+
rewriteHeaders: {
57+
rewrites: [
58+
{
59+
header: "Location",
60+
regex: "^http://mock-withings:8080/(.+)$",
61+
replacement: `${entrypoint}/$1`,
62+
},
63+
],
64+
},
65+
},
66+
},
67+
rewriteStrava: {
68+
plugin: {
69+
rewriteHeaders: {
70+
rewrites: [
71+
{
72+
header: "Location",
73+
regex: "^http://mock-strava:8080/(.+)$",
74+
replacement: `${entrypoint}/$1`,
75+
},
76+
],
77+
},
78+
},
79+
},
80+
};
81+
82+
const services = {
83+
client: {
84+
loadBalancer: {
85+
servers: [
86+
{
87+
url: "http://client:80",
88+
},
89+
],
90+
},
91+
},
92+
server: {
93+
loadBalancer: {
94+
servers: [
95+
{
96+
url: "http://server:8080",
97+
},
98+
],
99+
},
100+
},
101+
mockBackupTool: {
102+
loadBalancer: {
103+
servers: [
104+
{
105+
url: "http://mock-backup-tool:8080",
106+
},
107+
],
108+
},
109+
},
110+
mockWithings: {
111+
loadBalancer: {
112+
servers: [
113+
{
114+
url: "http://mock-withings:8080",
115+
},
116+
],
117+
},
118+
},
119+
mockStrava: {
120+
loadBalancer: {
121+
servers: [
122+
{
123+
url: "http://mock-strava:8080",
124+
},
125+
],
126+
},
127+
},
128+
chrome: {
129+
loadBalancer: {
130+
servers: [
131+
{
132+
url: "http://chrome:4444",
133+
},
134+
],
135+
},
136+
},
137+
};
138+
139+
server.on("request", async (request, response) => {
140+
console.log(request.url);
141+
142+
response.end(
143+
JSON.stringify({
144+
http: {
145+
routers,
146+
middlewares,
147+
services,
148+
},
149+
})
150+
);
151+
});
152+
153+
process.on("SIGINT", () => server.close(() => process.exit()));
154+
process.on("SIGTERM", () => server.close(() => process.exit()));
155+
156+
server.listen(PORT, () => {
157+
console.log(`starting server at port ${PORT}`);
158+
});

test/reverse_proxy/traefik_dynamic_conf.yml

-70
This file was deleted.
+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
entryPoints:
22
web:
3-
address: ":80"
3+
address: ":80"
44
providers:
5-
file:
6-
filename: /etc/traefik/traefik_dynamic_conf.yml
5+
http:
6+
endpoint: "http://traefik_dynamic_conf:8080"
7+
experimental:
8+
plugins:
9+
rewriteHeaders:
10+
modulename: "github.com/XciD/traefik-plugin-rewrite-headers"
11+
version: "v0.0.4"

0 commit comments

Comments
 (0)