Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb25f8489e | |||
| 21937db8de | |||
| 28b689cac0 | |||
| cc04a1a8bb |
4
.env
4
.env
@ -1,7 +1,7 @@
|
||||
ENVIRONMENT=local
|
||||
DATABASE_PASSWORD=QgSvstSjoc6fKphMzNgT3SliNY10eSRS
|
||||
DATABASE_PASSWORD=tIr4TJ0qUwGVM0rlQSe3W7Tgpi33zPbk
|
||||
DATABASE_ROLE=agreego_admin
|
||||
DATABASE_HOST=127.1.27.9
|
||||
DATABASE_HOST=127.1.27.4
|
||||
DATABASE_PORT=5432
|
||||
POSTGRES_PASSWORD=xzIq5JT0xY3F+2m1GtnrKDdK29sNSXVVYZHPKJVh8pI=
|
||||
DATABASE_NAME=agreego
|
||||
|
||||
44
src/lib.rs
44
src/lib.rs
@ -48,22 +48,24 @@ fn cache_json_schema(schema_id: &str, schema: JsonB) -> JsonB {
|
||||
}
|
||||
Err(e) => {
|
||||
let error = match &e {
|
||||
CompileError::ValidationError { url: _url, src } => { // Prefix url with _
|
||||
json!({
|
||||
"message": format!("Schema '{}' failed validation against its metaschema: {}", schema_id, src),
|
||||
"schema_path": schema_path,
|
||||
"error": format!("{:?}", src),
|
||||
})
|
||||
CompileError::ValidationError { url: _url, src } => {
|
||||
// Collect leaf errors from the meta-schema validation failure
|
||||
let mut error_list = Vec::new();
|
||||
collect_leaf_errors(src, &mut error_list);
|
||||
// Return the flat list directly
|
||||
json!(error_list)
|
||||
}
|
||||
_ => {
|
||||
let _error_type = format!("{:?}", e).split('(').next().unwrap_or("Unknown").to_string(); // Prefix error_type with _
|
||||
// Keep existing handling for other compilation errors
|
||||
let _error_type = format!("{:?}", e).split('(').next().unwrap_or("Unknown").to_string();
|
||||
json!({
|
||||
"message": format!("Schema '{}' compilation failed: {}", schema_id, e),
|
||||
"schema_path": schema_path,
|
||||
"error": format!("{:?}", e),
|
||||
"detail": format!("{:?}", e),
|
||||
})
|
||||
}
|
||||
};
|
||||
// Ensure the outer structure remains { success: false, error: ... }
|
||||
JsonB(json!({
|
||||
"success": false,
|
||||
"error": error
|
||||
@ -80,11 +82,9 @@ fn validate_json_schema(schema_id: &str, instance: JsonB) -> JsonB {
|
||||
match cache.id_to_index.get(schema_id) {
|
||||
None => JsonB(json!({
|
||||
"success": false,
|
||||
"errors": [json!({
|
||||
"message": format!("Schema with id '{}' not found in cache", schema_id),
|
||||
"schema_path": "",
|
||||
"instance_path": ""
|
||||
})]
|
||||
"error": {
|
||||
"message": format!("Schema with id '{}' not found in cache", schema_id)
|
||||
}
|
||||
})),
|
||||
Some(sch_index) => {
|
||||
let instance_value: Value = instance.0;
|
||||
@ -93,7 +93,12 @@ fn validate_json_schema(schema_id: &str, instance: JsonB) -> JsonB {
|
||||
Err(validation_error) => {
|
||||
// Directly use the result of format_validation_error
|
||||
// which now includes the top-level success indicator and flat error list
|
||||
JsonB(format_validation_error(&validation_error))
|
||||
let mut error_list = Vec::new();
|
||||
collect_leaf_errors(&validation_error, &mut error_list);
|
||||
JsonB(json!({
|
||||
"success": false,
|
||||
"error": error_list // Flat list of specific errors
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,17 +127,6 @@ fn collect_leaf_errors(error: &ValidationError, errors_list: &mut Vec<Value>) {
|
||||
}
|
||||
}
|
||||
|
||||
// Formats validation errors into a flat list JSON structure
|
||||
fn format_validation_error(error: &ValidationError) -> Value {
|
||||
let mut all_errors = Vec::new();
|
||||
collect_leaf_errors(error, &mut all_errors);
|
||||
|
||||
json!({
|
||||
"success": false,
|
||||
"errors": all_errors // Flat list of specific errors
|
||||
})
|
||||
}
|
||||
|
||||
#[pg_extern(strict, parallel_safe)]
|
||||
fn json_schema_cached(schema_id: &str) -> bool {
|
||||
let cache = SCHEMA_CACHE.read().unwrap();
|
||||
|
||||
140
src/tests.rs
140
src/tests.rs
@ -33,21 +33,23 @@ macro_rules! assert_failure_with_json {
|
||||
($result:expr, $expected_error_count:expr, $expected_first_message_contains:expr, $fmt:literal $(, $($args:tt)*)?) => {
|
||||
let json_result = &$result.0;
|
||||
let success = json_result.get("success").and_then(Value::as_bool);
|
||||
let errors_opt = json_result.get("errors").and_then(Value::as_array);
|
||||
let error_val_opt = json_result.get("error"); // Changed key
|
||||
let base_msg = format!($fmt $(, $($args)*)?);
|
||||
|
||||
if success != Some(false) {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected failure, success was not false): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
match errors_opt {
|
||||
Some(errors) => {
|
||||
if errors.len() != $expected_error_count {
|
||||
match error_val_opt {
|
||||
Some(error_val) => {
|
||||
if error_val.is_array() {
|
||||
let errors_array = error_val.as_array().unwrap();
|
||||
if errors_array.len() != $expected_error_count {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (wrong error count): Expected {} errors, got {}. {}\nResult JSON:\n{}", $expected_error_count, errors.len(), base_msg, pretty_json);
|
||||
panic!("Assertion Failed (wrong error count): Expected {} errors, got {}. {}\nResult JSON:\n{}", $expected_error_count, errors_array.len(), base_msg, pretty_json);
|
||||
}
|
||||
if $expected_error_count > 0 {
|
||||
let first_error_message = errors[0].get("message").and_then(Value::as_str);
|
||||
let first_error_message = errors_array[0].get("message").and_then(Value::as_str);
|
||||
match first_error_message {
|
||||
Some(msg) => {
|
||||
if !msg.contains($expected_first_message_contains) {
|
||||
@ -57,14 +59,37 @@ macro_rules! assert_failure_with_json {
|
||||
}
|
||||
None => {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (first error has no 'message' string): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
panic!("Assertion Failed (first error in array has no 'message' string): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if error_val.is_object() {
|
||||
// Handle single error object case (like 'schema not found')
|
||||
if $expected_error_count != 1 {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (wrong error count): Expected {} errors, but got a single error object. {}\nResult JSON:\n{}", $expected_error_count, base_msg, pretty_json);
|
||||
}
|
||||
let message = error_val.get("message").and_then(Value::as_str);
|
||||
match message {
|
||||
Some(msg) => {
|
||||
if !msg.contains($expected_first_message_contains) {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (error message mismatch): Expected object message contains '{}', got: '{}'. {}\nResult JSON:\n{}", $expected_first_message_contains, msg, base_msg, pretty_json);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected 'errors' array, but none found): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
panic!("Assertion Failed (error object has no 'message' string): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed ('error' value is not an array or object): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected 'error' key, but none found): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -78,23 +103,35 @@ macro_rules! assert_failure_with_json {
|
||||
($result:expr, $expected_error_count:expr, $fmt:literal $(, $($args:tt)*)?) => {
|
||||
let json_result = &$result.0;
|
||||
let success = json_result.get("success").and_then(Value::as_bool);
|
||||
let errors_opt = json_result.get("errors").and_then(Value::as_array);
|
||||
let error_val_opt = json_result.get("error"); // Changed key
|
||||
let base_msg = format!($fmt $(, $($args)*)?);
|
||||
|
||||
if success != Some(false) {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected failure, success was not false): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
match errors_opt {
|
||||
Some(errors) => {
|
||||
if errors.len() != $expected_error_count {
|
||||
match error_val_opt {
|
||||
Some(error_val) => {
|
||||
if error_val.is_array() {
|
||||
let errors_array = error_val.as_array().unwrap();
|
||||
if errors_array.len() != $expected_error_count {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (wrong error count): Expected {} errors, got {}. {}\nResult JSON:\n{}", $expected_error_count, errors.len(), base_msg, pretty_json);
|
||||
panic!("Assertion Failed (wrong error count): Expected {} errors, got {}. {}\nResult JSON:\n{}", $expected_error_count, errors_array.len(), base_msg, pretty_json);
|
||||
}
|
||||
} else if error_val.is_object() {
|
||||
if $expected_error_count != 1 {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (wrong error count): Expected {} errors, but got a single error object. {}\nResult JSON:\n{}", $expected_error_count, base_msg, pretty_json);
|
||||
}
|
||||
// Count check passes if expected is 1 and got object
|
||||
} else {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed ('error' value is not an array or object): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected 'errors' array, but none found): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
panic!("Assertion Failed (expected 'error' key, but none found): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -108,23 +145,31 @@ macro_rules! assert_failure_with_json {
|
||||
($result:expr, $fmt:literal $(, $($args:tt)*)?) => {
|
||||
let json_result = &$result.0;
|
||||
let success = json_result.get("success").and_then(Value::as_bool);
|
||||
let errors_opt = json_result.get("errors").and_then(Value::as_array);
|
||||
let error_val_opt = json_result.get("error"); // Changed key
|
||||
let base_msg = format!($fmt $(, $($args)*)?);
|
||||
|
||||
if success != Some(false) {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected failure, success was not false): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
match errors_opt {
|
||||
Some(errors) => {
|
||||
if errors.is_empty() {
|
||||
match error_val_opt {
|
||||
Some(error_val) => {
|
||||
if error_val.is_object() {
|
||||
// OK: single error object is a failure
|
||||
} else if error_val.is_array() {
|
||||
if error_val.as_array().unwrap().is_empty() {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected errors, but errors array is empty): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
panic!("Assertion Failed (expected errors, but 'error' array is empty): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
// OK: non-empty error array is a failure
|
||||
} else {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed ('error' value is not an array or object): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected 'errors' array, but none found): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
panic!("Assertion Failed (expected 'error' key, but none found): {}\nResult JSON:\n{}", base_msg, pretty_json);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -164,14 +209,14 @@ fn test_cache_and_validate_json_schema() {
|
||||
// Invalid type
|
||||
let invalid_result_type = validate_json_schema(schema_id, jsonb(invalid_instance_type));
|
||||
assert_failure_with_json!(invalid_result_type, 1, "must be >=0", "Validation with invalid type should fail.");
|
||||
let errors_type = invalid_result_type.0["errors"].as_array().unwrap();
|
||||
let errors_type = invalid_result_type.0["error"].as_array().unwrap(); // Check 'error', expect array
|
||||
assert_eq!(errors_type[0]["instance_path"], "/age");
|
||||
assert_eq!(errors_type[0]["schema_path"], "urn:my_schema#/properties/age");
|
||||
|
||||
// Missing field
|
||||
let invalid_result_missing = validate_json_schema(schema_id, jsonb(invalid_instance_missing));
|
||||
assert_failure_with_json!(invalid_result_missing, 1, "missing properties 'age'", "Validation with missing field should fail.");
|
||||
let errors_missing = invalid_result_missing.0["errors"].as_array().unwrap();
|
||||
let errors_missing = invalid_result_missing.0["error"].as_array().unwrap(); // Check 'error', expect array
|
||||
assert_eq!(errors_missing[0]["instance_path"], "");
|
||||
assert_eq!(errors_missing[0]["schema_path"], "urn:my_schema#");
|
||||
|
||||
@ -179,9 +224,10 @@ fn test_cache_and_validate_json_schema() {
|
||||
let non_existent_id = "non_existent_schema";
|
||||
let invalid_schema_result = validate_json_schema(non_existent_id, jsonb(json!({})));
|
||||
assert_failure_with_json!(invalid_schema_result, 1, "Schema with id 'non_existent_schema' not found", "Validation with non-existent schema should fail.");
|
||||
let errors_notfound = invalid_schema_result.0["errors"].as_array().unwrap();
|
||||
assert_eq!(errors_notfound[0]["schema_path"], ""); // Schema path is empty for this error type
|
||||
assert_eq!(errors_notfound[0]["instance_path"], ""); // Instance path is empty
|
||||
// Check 'error' is an object for 'schema not found'
|
||||
let error_notfound_obj = invalid_schema_result.0["error"].as_object().expect("'error' should be an object for schema not found");
|
||||
assert!(error_notfound_obj.contains_key("message")); // Check message exists
|
||||
// Removed checks for schema_path/instance_path as they aren't added in lib.rs for this case
|
||||
}
|
||||
|
||||
#[pg_test]
|
||||
@ -189,7 +235,7 @@ fn test_validate_json_schema_not_cached() {
|
||||
clear_json_schemas(); // Call clear directly
|
||||
let instance = json!({ "foo": "bar" });
|
||||
let result = validate_json_schema("non_existent_schema", jsonb(instance));
|
||||
// Use the updated macro
|
||||
// Use the updated macro, expecting count 1 and specific message (handles object case)
|
||||
assert_failure_with_json!(result, 1, "Schema with id 'non_existent_schema' not found", "Validation with non-existent schema should fail.");
|
||||
}
|
||||
|
||||
@ -205,26 +251,24 @@ fn test_cache_invalid_json_schema() {
|
||||
|
||||
let cache_result = cache_json_schema(schema_id, jsonb(invalid_schema));
|
||||
|
||||
// Manually check the structure for cache_json_schema failure
|
||||
let json_result = &cache_result.0;
|
||||
let success = json_result.get("success").and_then(Value::as_bool);
|
||||
let error_obj = json_result.get("error").and_then(Value::as_object);
|
||||
// Expect 2 leaf errors because the meta-schema validation fails at the type value
|
||||
// and within the type array itself.
|
||||
assert_failure_with_json!(
|
||||
cache_result,
|
||||
2, // Expect exactly two leaf errors
|
||||
"value must be one of", // Check message substring (present in both)
|
||||
"Caching invalid schema should fail with specific meta-schema validation errors."
|
||||
);
|
||||
|
||||
if success != Some(false) {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected failure, success was not false): Caching invalid schema should fail.\nResult JSON:\n{}", pretty_json);
|
||||
}
|
||||
if error_obj.is_none() {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected 'error' object, but none found): Caching invalid schema should return an error object.\nResult JSON:\n{}", pretty_json);
|
||||
}
|
||||
// Check specific fields within the error object
|
||||
let message = error_obj.unwrap().get("message").and_then(Value::as_str);
|
||||
// Updated check based on the actual error message seen in the logs
|
||||
if message.map_or(true, |m| !m.contains("failed validation against its metaschema") || !m.contains("/type/0': value must be one of")) {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (error message mismatch): Expected metaschema validation failure message containing '/type/0' error detail.\nResult JSON:\n{}", pretty_json);
|
||||
}
|
||||
// Ensure the error is an array and check specifics
|
||||
let error_array = cache_result.0["error"].as_array().expect("Error field should be an array");
|
||||
assert_eq!(error_array.len(), 2);
|
||||
// Note: Order might vary depending on boon's internal processing, check both possibilities or sort.
|
||||
// Assuming the order shown in the logs for now:
|
||||
assert_eq!(error_array[0]["instance_path"], "/type");
|
||||
assert!(error_array[0]["message"].as_str().unwrap().contains("value must be one of"));
|
||||
assert_eq!(error_array[1]["instance_path"], "/type/0");
|
||||
assert!(error_array[1]["message"].as_str().unwrap().contains("value must be one of"));
|
||||
}
|
||||
|
||||
#[pg_test]
|
||||
@ -292,7 +336,6 @@ fn test_validate_json_schema_oneof_validation_errors() {
|
||||
// Expect 2 leaf errors: one for maxLength (branch 0), one for missing prop (branch 1)
|
||||
// Check the first error message reported by boon (maxLength).
|
||||
assert_failure_with_json!(result_invalid_string, 2, "length must be <=5", "Validation with invalid string length should have 2 leaf errors");
|
||||
let _errors_string = result_invalid_string.0["errors"].as_array().unwrap(); // Prefix with _
|
||||
|
||||
// --- Test case 2: Fails number minimum (in branch 1) AND missing string_prop (in branch 0) ---
|
||||
let invalid_number_instance = json!({ "number_prop": 5 });
|
||||
@ -300,7 +343,6 @@ fn test_validate_json_schema_oneof_validation_errors() {
|
||||
// Expect 2 leaf errors: one for minimum (branch 1), one for missing prop (branch 0)
|
||||
// Check the first error message reported by boon (missing prop).
|
||||
assert_failure_with_json!(result_invalid_number, 2, "missing properties 'string_prop'", "Validation with invalid number should have 2 leaf errors");
|
||||
let _errors_number = result_invalid_number.0["errors"].as_array().unwrap(); // Prefix with _
|
||||
|
||||
// --- Test case 3: Fails type check (not object) for both branches ---
|
||||
// Input: boolean, expected object for both branches
|
||||
@ -309,7 +351,6 @@ fn test_validate_json_schema_oneof_validation_errors() {
|
||||
// Expect 2 leaf errors, one "Type" error for each branch
|
||||
// Check the first error reported by boon (want object).
|
||||
assert_failure_with_json!(result_invalid_bool, 2, "want object", "Validation with invalid bool should have 2 leaf errors");
|
||||
let _errors_bool = result_invalid_bool.0["errors"].as_array().unwrap(); // Prefix with _
|
||||
|
||||
// --- Test case 4: Fails missing required for both branches ---
|
||||
// Input: empty object, expected string_prop (branch 0) OR number_prop (branch 1)
|
||||
@ -318,7 +359,6 @@ fn test_validate_json_schema_oneof_validation_errors() {
|
||||
// Expect 2 leaf errors: one required error for branch 0, one required error for branch 1
|
||||
// Check the first error reported by boon (missing string_prop).
|
||||
assert_failure_with_json!(result_empty_obj, 2, "missing properties 'string_prop'", "Validation with empty object should have 2 leaf errors");
|
||||
let _errors_empty = result_empty_obj.0["errors"].as_array().unwrap(); // Prefix with _
|
||||
}
|
||||
|
||||
#[pg_test]
|
||||
@ -338,7 +378,7 @@ fn test_clear_json_schemas() {
|
||||
|
||||
let instance = json!("test");
|
||||
let validate_result = validate_json_schema(schema_id, jsonb(instance));
|
||||
// Use the updated macro
|
||||
// Use the updated macro, expecting count 1 and specific message (handles object case)
|
||||
assert_failure_with_json!(validate_result, 1, "Schema with id 'schema_to_clear' not found", "Validation should fail after clearing schemas.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user