mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-11 17:31:46 +00:00
api-macro: more invocation tests for api methods
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
679ad01c03
commit
58158b495e
@ -38,8 +38,17 @@ use serde_json::{json, Value};
|
|||||||
/// Create or verify authentication ticket.
|
/// Create or verify authentication ticket.
|
||||||
///
|
///
|
||||||
/// Returns: A ticket.
|
/// Returns: A ticket.
|
||||||
pub fn create_ticket(_param: Value) -> Result<Value, Error> {
|
pub fn create_ticket(param: Value) -> Result<Value, Error> {
|
||||||
panic!("implement me");
|
let obj = param.as_object().expect("expected object parameter");
|
||||||
|
assert!(obj.contains_key("username"));
|
||||||
|
assert!(obj.contains_key("password"));
|
||||||
|
let user = obj["username"].as_str().expect("expected a username");
|
||||||
|
assert!(obj["password"].as_str().is_some());
|
||||||
|
Ok(json!({
|
||||||
|
"username": user,
|
||||||
|
"ticket": "<TICKET>",
|
||||||
|
"CSRFPreventionToken": "<TOKEN>",
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -293,4 +302,15 @@ fn test_invocations() {
|
|||||||
&mut env,
|
&mut env,
|
||||||
)
|
)
|
||||||
.expect("func with option should work");
|
.expect("func with option should work");
|
||||||
|
|
||||||
|
let login = api_function_create_ticket(
|
||||||
|
json!({"username":"hello","password":"world"}),
|
||||||
|
&API_METHOD_CREATE_TICKET,
|
||||||
|
&mut env,
|
||||||
|
)
|
||||||
|
.expect("expected a ticket");
|
||||||
|
let login = login.as_object().expect("expected a valid result");
|
||||||
|
assert_eq!(login["username"], "hello");
|
||||||
|
assert_eq!(login["ticket"], "<TICKET>");
|
||||||
|
assert_eq!(login["CSRFPreventionToken"], "<TOKEN>");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user