Skip to content

Commit

Permalink
fix proxy, html5 and selenium issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mucsi96 committed Oct 26, 2023
1 parent f94a1cd commit e4d75ab
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 97 deletions.
5 changes: 0 additions & 5 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,3 @@ services:
chmod 600 /tmp/pgpass;
/entrypoint.sh;
"
chrome:
image: seleniarm/standalone-chromium:116.0-chromedriver-116.0-grid-4.10.0-20230828
restart: unless-stopped
shm_size: '2gb'
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ Converter<OAuth2AuthorizationCodeGrantRequest, MultiValueMap<String, String>> st
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.add(OAuth2ParameterNames.CLIENT_ID, request.getClientRegistration().getClientId());
parameters.add(OAuth2ParameterNames.CLIENT_SECRET, request.getClientRegistration().getClientSecret());
// parameters.add(OAuth2ParameterNames.CODE,
// request.getAuthorizationExchange().getAuthorizationResponse().getCode());
// parameters.add(OAuth2ParameterNames.GRANT_TYPE, "authorization_code");
return parameters;
};
}
Expand All @@ -121,8 +118,6 @@ Converter<OAuth2RefreshTokenGrantRequest, MultiValueMap<String, String>> stravaR
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.add(OAuth2ParameterNames.CLIENT_ID, request.getClientRegistration().getClientId());
parameters.add(OAuth2ParameterNames.CLIENT_SECRET, request.getClientRegistration().getClientSecret());
// parameters.add(OAuth2ParameterNames.GRANT_TYPE, "refresh_token");
// parameters.add(OAuth2ParameterNames.REFRESH_TOKEN, request.getRefreshToken().getTokenValue());
return parameters;
};
}
Expand Down
21 changes: 11 additions & 10 deletions test/docker-compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ const os = require("os");
const arch = os.arch();
const dockerNetwork = process.env.DOCKER_NETWORK;
const workspaceRoot = process.env.WORKSPACE_ROOT ?? "..";
const gatewayPort = 9780;
const gatewayHost = `http://${
dockerNetwork ? "reverse-proxy" : `localhost:${gatewayPort}`
}`;

const config = {
version: "3.8",
Expand Down Expand Up @@ -50,12 +46,12 @@ const config = {
SPRING_ACTUATOR_PORT: 8082,
SPRING_ADMIN_SERVER_HOST: "localhost",
SPRING_ADMIN_SERVER_PORT: 9090,
WEBDRIVER_API_URI: `${gatewayHost}/chrome/wd/hub`,
WITHINGS_ACCOUNTS_URI: `${gatewayHost}/withings`,
WITHINGS_API_URI: `${gatewayHost}/withings`,
WEBDRIVER_API_URI: "http://chrome:4444/chrome/wd/hub",
WITHINGS_ACCOUNTS_URI: "http://mock-withings:8080/withings",
WITHINGS_API_URI: "http://mock-withings:8080/withings",
WITHINGS_CLIENT_ID: "withings-client-id",
WITHINGS_CLIENT_SECRET: "withings-client-secret",
STRAVA_API_URI: `${gatewayHost}/strava`,
STRAVA_API_URI: "http://mock-strava:8080/strava",
STRAVA_CLIENT_ID: "strava-client-id",
STRAVA_CLIENT_SECRET: "strava-client-secret",
},
Expand All @@ -72,12 +68,17 @@ const config = {
},
},
},
traefik_dynamic_conf: {
build: "./reverse_proxy",
environment: {
DOCKER_NETWORK: process.env.DOCKER_NETWORK,
},
},
"reverse-proxy": {
image: "traefik",
ports: [`${gatewayPort}:80`],
ports: ["9780:80"],
volumes: [
`${workspaceRoot}/test/reverse_proxy/traefik_static_conf.yml:/etc/traefik/traefik.yml`,
`${workspaceRoot}/test/reverse_proxy/traefik_dynamic_conf.yml:/etc/traefik/traefik_dynamic_conf.yml`,
],
},
chrome: {
Expand Down
11 changes: 7 additions & 4 deletions test/mock_strava/authorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ function authozire(request, response) {
location.searchParams.append("code", "authorization-code");

response.writeHead(200, {
'Content-Type': 'text/html;charset=utf-8'
})
return response.end(`
"Content-Type": "text/html;charset=utf-8",
});
const responseBody = `
<!DOCTYPE html>
<h1>Mock Strava</h1>
<a href="${location.toString()}">Authorize</a>
`);
`;
console.log("Response: ", responseBody);
return response.end(responseBody);
}

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions test/mock_withings/authorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function authozire(request, response) {
"Content-Type": "text/html;charset=utf-8",
});
const responseBody = `
<!DOCTYPE html>
<h1>Mock Withings</h1>
<a href="${location.toString()}">Authorize</a>
`;
Expand Down
9 changes: 9 additions & 0 deletions test/reverse_proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:18

WORKDIR /usr/src/app

COPY . .

EXPOSE 8080

CMD [ "node", "traefik_dynamic_conf.js" ]
158 changes: 158 additions & 0 deletions test/reverse_proxy/traefik_dynamic_conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
const { createServer } = require("http");
const PORT = 8080;
const server = createServer();

const entrypoint = process.env.DOCKER_NETWORKE
? "http://reverse-proxy"
: "http://localhost:9780";

const routers = {
client: {
entryPoints: ["web"],
service: "client",
rule: "PathPrefix(`/`)",
},
servers: {
entryPoints: ["web"],
middlewares: ["authHeaders", "rewriteWithings", "rewriteStrava"],
service: "server",
rule: "PathPrefix(`/api`)",
},
mockBackupTool: {
entryPoints: ["web"],
service: "mockBackupTool",
rule: "Path(`/db/last-backup-time`)",
},
mockWithings: {
entryPoints: ["web"],
service: "mockWithings",
rule: "PathPrefix(`/withings`)",
},
mockStrava: {
entryPoints: ["web"],
service: "mockStrava",
rule: "PathPrefix(`/strava`)",
},
chrome: {
entryPoints: ["web"],
service: "chrome",
rule: "PathPrefix(`/chrome`)",
},
};

const middlewares = {
authHeaders: {
headers: {
customRequestHeaders: {
"Remote-User": "rob",
"Remote-Groups": "user",
"Remote-Name": "Robert White",
"Remote-Email": "robert.white@mockemail.com",
},
},
},
rewriteWithings: {
plugin: {
rewriteHeaders: {
rewrites: [
{
header: "Location",
regex: "^http://mock-withings:8080/(.+)$",
replacement: `${entrypoint}/$1`,
},
],
},
},
},
rewriteStrava: {
plugin: {
rewriteHeaders: {
rewrites: [
{
header: "Location",
regex: "^http://mock-strava:8080/(.+)$",
replacement: `${entrypoint}/$1`,
},
],
},
},
},
};

const services = {
client: {
loadBalancer: {
servers: [
{
url: "http://client:80",
},
],
},
},
server: {
loadBalancer: {
servers: [
{
url: "http://server:8080",
},
],
},
},
mockBackupTool: {
loadBalancer: {
servers: [
{
url: "http://mock-backup-tool:8080",
},
],
},
},
mockWithings: {
loadBalancer: {
servers: [
{
url: "http://mock-withings:8080",
},
],
},
},
mockStrava: {
loadBalancer: {
servers: [
{
url: "http://mock-strava:8080",
},
],
},
},
chrome: {
loadBalancer: {
servers: [
{
url: "http://chrome:4444",
},
],
},
},
};

server.on("request", async (request, response) => {
console.log(request.url);

response.end(
JSON.stringify({
http: {
routers,
middlewares,
services,
},
})
);
});

process.on("SIGINT", () => server.close(() => process.exit()));
process.on("SIGTERM", () => server.close(() => process.exit()));

server.listen(PORT, () => {
console.log(`starting server at port ${PORT}`);
});
70 changes: 0 additions & 70 deletions test/reverse_proxy/traefik_dynamic_conf.yml

This file was deleted.

11 changes: 8 additions & 3 deletions test/reverse_proxy/traefik_static_conf.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
entryPoints:
web:
address: ":80"
address: ":80"
providers:
file:
filename: /etc/traefik/traefik_dynamic_conf.yml
http:
endpoint: "http://traefik_dynamic_conf:8080"
experimental:
plugins:
rewriteHeaders:
modulename: "github.com/XciD/traefik-plugin-rewrite-headers"
version: "v0.0.4"

0 comments on commit e4d75ab

Please sign in to comment.