Mercurial > crates > nonstick
comparison testharness/src/lib.rs @ 172:6727cbe56f4a
Test environment variable setting; minor cleanup.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Fri, 25 Jul 2025 21:02:53 -0400 |
| parents | e27c5c667a5a |
| children | 46e8ce5cd5d1 |
comparison
equal
deleted
inserted
replaced
| 171:e27c5c667a5a | 172:6727cbe56f4a |
|---|---|
| 1 //! The nonstick library | 1 //! The nonstick library |
| 2 | 2 |
| 3 use crate::nonstick::items::ItemsMut; | 3 use crate::nonstick::items::ItemsMut; |
| 4 use crate::nonstick::EnvironMapMut; | |
| 4 use std::cell::Cell; | 5 use std::cell::Cell; |
| 5 extern crate nonstick; | 6 extern crate nonstick; |
| 6 | 7 |
| 7 use nonstick::conv::{ErrorMsg, InfoMsg, MaskedQAndA, QAndA}; | 8 use nonstick::conv::{ErrorMsg, InfoMsg, MaskedQAndA, QAndA}; |
| 8 use nonstick::{ | 9 use nonstick::{ |
| 53 Err(ErrorCode::Abort) | 54 Err(ErrorCode::Abort) |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 | 57 |
| 57 fn account_management(handle: &mut M, _: Vec<&CStr>, _: AuthnFlags) -> nonstick::Result<()> { | 58 fn account_management(handle: &mut M, _: Vec<&CStr>, _: AuthnFlags) -> nonstick::Result<()> { |
| 58 let value: &Cell<i32> = match handle.username(None)?.as_bytes() { | 59 match handle.username(None)?.as_bytes() { |
| 59 b"initial" => return Err(ErrorCode::AccountExpired), | 60 b"initial" => return Err(ErrorCode::AccountExpired), |
| 60 b"updated-in-process" => handle.get_module_data("florgus"), | 61 b"updated-in-process" => (), |
| 61 _ => return Err(ErrorCode::UserUnknown), | 62 _ => return Err(ErrorCode::UserUnknown), |
| 62 } | 63 }; |
| 63 .ok_or(ErrorCode::SessionError)?; | 64 let value: &Cell<i32> = handle |
| 65 .get_module_data("florgus") | |
| 66 .ok_or(ErrorCode::SessionError)?; | |
| 64 let florgus_str: Option<&i32> = handle.get_module_data("florgus"); | 67 let florgus_str: Option<&i32> = handle.get_module_data("florgus"); |
| 65 if let Some(s) = florgus_str { | 68 if let Some(s) = florgus_str { |
| 66 error!( | 69 error!( |
| 67 handle, | 70 handle, |
| 68 "module_data type mismatch: florgus = <{s}> but should not be set" | 71 "module_data type mismatch: florgus = <{s}> but should not be set" |
| 70 } | 73 } |
| 71 if value.get() != 99 { | 74 if value.get() != 99 { |
| 72 error!(handle, "wrong value! {}", value.get()); | 75 error!(handle, "wrong value! {}", value.get()); |
| 73 return Err(ErrorCode::AuthTokError); | 76 return Err(ErrorCode::AuthTokError); |
| 74 } | 77 } |
| 78 handle.environ_mut().insert("nin", "nine inch nails"); | |
| 75 let password = handle.authtok(None)?; | 79 let password = handle.authtok(None)?; |
| 76 if password.as_bytes() == b"valid" { | 80 if password.as_bytes() == b"valid" { |
| 77 Err(ErrorCode::NewAuthTokRequired) | 81 Err(ErrorCode::NewAuthTokRequired) |
| 78 } else { | 82 } else { |
| 79 Ok(()) | 83 Ok(()) |
