Skip to content

Commit 887533e

Browse files
committed
Fix hurl tests, enable them in gh action and disable SAML hurl tests - broken
1 parent f14da48 commit 887533e

8 files changed

Lines changed: 110 additions & 105 deletions

File tree

.github/workflows/test.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ jobs:
2727
runs-on: ubuntu-latest
2828
steps:
2929
- uses: actions/checkout@v4
30-
31-
- name: Install Rust toolchain
32-
uses: actions-rust-lang/setup-rust-toolchain@v1
30+
- uses: cachix/install-nix-action@v31
3331
with:
34-
cache: true
32+
nix_path: nixpkgs=channel:nixos-unstable
3533

3634
- name: Test
37-
run: cargo test --release --all-features
35+
run: nix develop --command bash -c "yarn install && yarn test"

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
cargo-criterion
2020
gnuplot # For benchmarks
2121
hurl
22+
watchexec
2223

2324
yarn
2425
];

hurl/authurl.hurl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ header "Location" startsWith "http://localhost:8081/asdf?a=b&magicentry_code=me_
2828

2929
# Make the initial request after returning to the service
3030
GET http://localhost:8080/auth-url/status
31-
X-Original-Uri: {{proxy_link}}
31+
X-Original-Url: {{proxy_link}}
3232
HTTP 200
3333
[Captures]
3434
proxy_session: cookie "magicentry_session_id"
3535

3636
GET http://localhost:8080/auth-url/status
37-
X-Original-Uri: http://localhost:8080/asdasdasdas
37+
X-Original-Url: http://localhost:8080/asdasdasdas
3838
[Cookies]
3939
magicentry_session_id: {{proxy_session}}
4040
HTTP 200

hurl/saml.hurl

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,53 +18,54 @@ Location: /
1818
[Captures]
1919
session: cookie "session_id"
2020

21-
GET http://localhost:8080/saml/sso
22-
[Cookies]
23-
session_id: {{session}}
24-
[Query]
25-
request: example
26-
HTTP 200
27-
[Captures]
28-
authcode: regex "code=(me_oidc_authcode_\\w+)&"
29-
30-
# Test the authorization redirect
31-
GET http://localhost:8080/saml/sso
32-
[Options]
33-
variable: redirect=https://openidconnect.net/callback
34-
[Query]
35-
client_id: my_client
36-
redirect_uri: {{redirect urlEncode}}
37-
scope: openid
38-
response_type: code
39-
HTTP 302
40-
[Captures]
41-
login: header "Location"
42-
43-
# Click the "Login" button in the UI that the proxy redirected us to
44-
POST {{login}}
45-
[Form]
46-
email: valid@example.com
47-
HTTP 200
48-
49-
# Set up a temporary webserver to serve the login link
50-
# python3 -m http.server -d hurl 8081
51-
GET http://localhost:8081/.link.txt
52-
HTTP 200
53-
[Captures]
54-
link: body
55-
56-
# Visit the magic link that was sent
57-
GET {{link}}
58-
HTTP 302
59-
[Asserts]
60-
header "Location" startsWith "/oidc/authorize?"
61-
[Captures]
62-
session: cookie "session_id"
63-
authorize_link: header "Location"
64-
65-
GET http://localhost:8080{{authorize_link}}
66-
[Cookies]
67-
session_id: {{session}}
68-
HTTP 200
69-
[Asserts]
70-
body contains "https://openidconnect.net/callback?code=me_oidc_authcode_"
21+
# TODO: Use a normal XML SAML request (b64 encoded, deflated too?)
22+
# GET http://localhost:8080/saml/sso
23+
# [Cookies]
24+
# session_id: {{session}}
25+
# [Query]
26+
# request: example
27+
# HTTP 200
28+
# [Captures]
29+
# authcode: regex "code=(me_oidc_authcode_\\w+)&"
30+
#
31+
# # Test the authorization redirect
32+
# GET http://localhost:8080/saml/sso
33+
# [Options]
34+
# variable: redirect=https://openidconnect.net/callback
35+
# [Query]
36+
# client_id: my_client
37+
# redirect_uri: {{redirect urlEncode}}
38+
# scope: openid
39+
# response_type: code
40+
# HTTP 302
41+
# [Captures]
42+
# login: header "Location"
43+
#
44+
# # Click the "Login" button in the UI that the proxy redirected us to
45+
# POST {{login}}
46+
# [Form]
47+
# email: valid@example.com
48+
# HTTP 200
49+
#
50+
# # Set up a temporary webserver to serve the login link
51+
# # python3 -m http.server -d hurl 8081
52+
# GET http://localhost:8081/.link.txt
53+
# HTTP 200
54+
# [Captures]
55+
# link: body
56+
#
57+
# # Visit the magic link that was sent
58+
# GET {{link}}
59+
# HTTP 302
60+
# [Asserts]
61+
# header "Location" startsWith "/oidc/authorize?"
62+
# [Captures]
63+
# session: cookie "session_id"
64+
# authorize_link: header "Location"
65+
#
66+
# GET http://localhost:8080{{authorize_link}}
67+
# [Cookies]
68+
# session_id: {{session}}
69+
# HTTP 200
70+
# [Asserts]
71+
# body contains "https://openidconnect.net/callback?code=me_oidc_authcode_"

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,27 @@
55
"license": "GPL-3.0-or-later",
66
"scripts": {
77
"start": "concurrently 'npm:start-web' 'npm:start-e2e'",
8+
"build": "webpack build --mode production && tailwindcss --input static/css/main.css --output static/main.build.css --minify",
9+
810
"test": "cargo test --color always --features kube && concurrently --kill-others 'npm:start-e2e' 'npm:test-e2e'",
9-
"test-e2e": "hurl --test --jobs 1 ./hurl",
11+
"test-e2e": "until curl -sSf http://localhost:8080 >/dev/null; do sleep 1; done; hurl --test --jobs 1 ./hurl",
1012
"test-server": "cargo test --color always --features e2e-test",
13+
1114
"start-web": "concurrently 'npm:tailwind-dev' 'npm:webpack-dev'",
1215
"tailwind-dev": "tailwindcss --input static/css/main.css --output static/main.build.css --watch",
1316
"webpack-dev": "webpack watch --mode development",
14-
"build": "webpack build --mode production && tailwindcss --input static/css/main.css --output static/main.build.css --minify",
17+
1518
"start-e2e": "concurrently 'npm:start-server' 'npm:e2e-server'",
1619
"start-server": "RUST_LOG_STYLE=always CONFIG_FILE=config.sample.yaml watchexec --debounce 2 --watch ./Cargo.toml --watch ./src --watch ./static --watch ./benches --restart cargo run --color always --features e2e-test",
1720
"start-test": "RUST_LOG_STYLE=always watchexec --debounce 2 --watch ./Cargo.toml --watch ./src --watch ./static --watch ./benches --restart cargo test --color always --features kube",
1821
"e2e-server": "http-server hurl -p 8081",
22+
1923
"start-server-docs": "concurrently 'watchexec --debounce 2 --watch ./Cargo.toml --watch ./src cargo doc --color always --lib --features kube' 'browser-sync start --server ./target/doc --startPath magicentry --reload-delay 5000 --watch'"
2024
},
2125
"devDependencies": {
2226
"@tailwindcss/cli": "4",
2327
"browser-sync": "*",
24-
"concurrently": "9",
28+
"concurrently": "*",
2529
"http-server": "*",
2630
"tailwindcss": "4",
2731
"webpack": "5",

src/config.rs

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,16 @@ impl Default for ConfigFile {
112112
request_data : Some("to={email}&subject={title} Login&body=Click the link to login: <a href=\"{magic_link}\">Login</a>&type=text/html".to_string()),
113113
request_content_type: "application/x-www-form-urlencoded".to_string(),
114114

115-
webauthn_enable: true,
115+
webauthn_enable: true,
116116

117-
// force_https_redirects: true,
117+
// force_https_redirects: true,
118118

119-
users_file: None,
120-
users: vec![],
121-
services: Services(vec![]),
122-
}
119+
users_file: None,
120+
users: vec![],
121+
122+
services: Services(vec![]),
123123
}
124+
}
124125
}
125126

126127
impl ConfigFile {
@@ -152,17 +153,17 @@ impl ConfigFile {
152153
/// Note that live-updating the CONFIG_FILE environment variable
153154
/// is **NOT** supported
154155
pub async fn reload() -> crate::error::Result<()> {
155-
let mut config = CONFIG.write().await;
156-
log::info!("Reloading config from {}", CONFIG_FILE.as_str());
157-
let mut new_config =
158-
serde_yaml::from_str::<ConfigFile>(&std::fs::read_to_string(CONFIG_FILE.as_str())?)?;
159-
if let Some(users_file) = &new_config.users_file {
160-
new_config.users =
161-
serde_yaml::from_str::<Vec<User>>(&std::fs::read_to_string(users_file)?)?;
162-
}
163-
*config = new_config;
164-
Ok(())
165-
}
156+
let mut config = CONFIG.write().await;
157+
log::info!("Reloading config from {}", CONFIG_FILE.as_str());
158+
let mut new_config =
159+
serde_yaml::from_str::<ConfigFile>(&std::fs::read_to_string(CONFIG_FILE.as_str())?)?;
160+
if let Some(users_file) = &new_config.users_file {
161+
new_config.users =
162+
serde_yaml::from_str::<Vec<User>>(&std::fs::read_to_string(users_file)?)?;
163+
}
164+
*config = new_config;
165+
Ok(())
166+
}
166167

167168
/// Set up a file watcher that fires the [reload](ConfigFile::reload) method so
168169
/// that config file changes get automatically picked up
@@ -180,24 +181,24 @@ impl ConfigFile {
180181
}
181182
})
182183
}, watcher_config)
183-
.expect("Failed to create watcher for the config file");
184-
185-
watcher
186-
.watch(Path::new(CONFIG_FILE.as_str()), notify::RecursiveMode::NonRecursive)
187-
.expect("Failed to watch config file for changes");
188-
189-
if let Some(users_file) = CONFIG
190-
.try_read()
191-
.ok()
192-
.and_then(|c| c.users_file.clone())
193-
{
194-
watcher
195-
.watch(Path::new(&users_file), notify::RecursiveMode::NonRecursive)
196-
.expect("Failed to watch users file for changes");
197-
}
198-
199-
watcher
200-
}
184+
.expect("Failed to create watcher for the config file");
185+
186+
watcher
187+
.watch(Path::new(CONFIG_FILE.as_str()), notify::RecursiveMode::NonRecursive)
188+
.expect("Failed to watch config file for changes");
189+
190+
if let Some(users_file) = CONFIG
191+
.try_read()
192+
.ok()
193+
.and_then(|c| c.users_file.clone())
194+
{
195+
watcher
196+
.watch(Path::new(&users_file), notify::RecursiveMode::NonRecursive)
197+
.expect("Failed to watch users file for changes");
198+
}
199+
200+
watcher
201+
}
201202

202203
/// Read the SAML certificate from the [saml_cert_pem_path](ConfigFile::saml_cert_pem_path)
203204
/// filepath
@@ -214,14 +215,14 @@ impl ConfigFile {
214215
/// filepath
215216
pub fn get_saml_key(&self) -> Result<String, std::io::Error> {
216217
let data = std::fs::read_to_string(&self.saml_key_pem_path)?;
217-
Ok(data
218-
.lines()
219-
.filter(|line| {
220-
!line.contains("BEGIN PRIVATE KEY") && !line.contains("END PRIVATE KEY")
221-
})
222-
.collect::<String>()
223-
.replace("\n", ""))
224-
}
218+
Ok(data
219+
.lines()
220+
.filter(|line| {
221+
!line.contains("BEGIN PRIVATE KEY") && !line.contains("END PRIVATE KEY")
222+
})
223+
.collect::<String>()
224+
.replace("\n", ""))
225+
}
225226
}
226227

227228
/// Basic key-value store database schema for some minor config values,

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum AppErrorKind {
4343
// Proxy (auth-url) errors
4444
#[display("Missing auth_url code in (query string or cookie)")]
4545
MissingAuthURLCode,
46-
#[display("Could not parse X-Original-URI header (it is set but not valid)")]
46+
#[display("Could not parse X-Original-URL header (it is set but not valid)")]
4747
CouldNotParseXOriginalURIHeader,
4848
#[display("The provided return destination URL (`rd` query parameter) doesn't have a an origin that is allowed in the config")]
4949
InvalidReturnDestinationUrl,

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ concat-map@0.0.1:
806806
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
807807
integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==
808808

809-
concurrently@9:
809+
concurrently@*:
810810
version "9.2.0"
811811
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-9.2.0.tgz#233e3892ceb0b5db9fd49e9c8c739737a7b638b5"
812812
integrity sha512-IsB/fiXTupmagMW4MNp2lx2cdSN2FfZq78vF90LBB+zZHArbIQZjQtzXCiXnvTxCZSvXanTqFLWBjw2UkLx1SQ==

0 commit comments

Comments
 (0)