Dever v0.0.2
This commit is contained in:
commit
e6e175ebcf
816 files changed
+120349
No files matched your search
@@ -0,0 +1,78 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn secret_settings_and_command_inputs_validate_without_exposing_values() {
|
||||
let root = directory("secret");
|
||||
fs::write(root.join("app.dever"), r#"
|
||||
setting key: Secret
|
||||
setting count: Int
|
||||
sign(value: Text) (out: Int) { out = length(dever.crypto.hmacSha256(key, dever.bytes.fromText(value))) }
|
||||
input(key: Secret, count: Int) (out: Int) { out = length(dever.crypto.hmacSha256(key, dever.bytes.fromText(int.toText(count)))) }
|
||||
cmd sign = app.sign
|
||||
cmd input = app.input
|
||||
"#).unwrap();
|
||||
let path = root.to_str().unwrap();
|
||||
success(cli(&["fmt", path]));
|
||||
let (project, program) = analyze(&root);
|
||||
let artifact = build::build(&project, &program, "main", Profile::Dev, None).unwrap();
|
||||
let binary = root.join("application");
|
||||
artifact.publish(&binary).unwrap();
|
||||
drop(artifact);
|
||||
fs::create_dir(root.join("config")).unwrap();
|
||||
let config = root.join("config/setting.json");
|
||||
fs::write(
|
||||
&config,
|
||||
r#"{"module":{"main":{"main":{"key":"test-config-secret","count":1}}}}"#,
|
||||
)
|
||||
.unwrap();
|
||||
let run = |name, input| Command::new(&binary).args([name, input]).output().unwrap();
|
||||
let output = success(run("main.main.sign", r#"{"value":"abc"}"#));
|
||||
assert_eq!(
|
||||
serde_json::from_str::<serde_json::Value>(&output).unwrap()["data"],
|
||||
32
|
||||
);
|
||||
success(run(
|
||||
"main.main.input",
|
||||
r#"{"key":"test-input-secret","count":2}"#,
|
||||
));
|
||||
for input in [
|
||||
r#"{"key":"test-input-secret","count":"not-to-be-echoed"}"#,
|
||||
r#"{"key":123456789,"count":2}"#,
|
||||
] {
|
||||
let output = run("main.main.input", input);
|
||||
assert!(!output.status.success() && output.stdout.is_empty());
|
||||
let error = String::from_utf8(output.stderr).unwrap();
|
||||
assert!(
|
||||
error.contains("line") && error.contains("column"),
|
||||
"{error}"
|
||||
);
|
||||
for value in ["test-input-secret", "not-to-be-echoed", "123456789"] {
|
||||
assert!(!error.contains(value));
|
||||
}
|
||||
}
|
||||
fs::write(
|
||||
&config,
|
||||
r#"{"module":{"main":{"main":{"key":"test-config-secret","count":"not-to-be-echoed"}}}}"#,
|
||||
)
|
||||
.unwrap();
|
||||
let output = run("main.main.sign", r#"{"value":"abc"}"#);
|
||||
assert!(!output.status.success() && output.stdout.is_empty());
|
||||
let error = String::from_utf8(output.stderr).unwrap();
|
||||
assert!(error.contains("line") && error.contains("column"));
|
||||
assert!(!error.contains("test-config-secret") && !error.contains("not-to-be-echoed"));
|
||||
for source in [
|
||||
"setting key: Secret\nmain() (out: Secret) { out = key }",
|
||||
"type Box { key: Secret }\nencode(value: Box) (out: Json) { out = dever.json.encode(value) }",
|
||||
] {
|
||||
fs::write(root.join("app.dever"), source).unwrap();
|
||||
success(cli(&["fmt", path]));
|
||||
let output = cli(&[
|
||||
"build",
|
||||
path,
|
||||
"--output",
|
||||
root.join("rejected").to_str().unwrap(),
|
||||
]);
|
||||
assert!(!output.status.success());
|
||||
assert!(String::from_utf8_lossy(&output.stderr).contains("Secret cannot"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user