} catch (LoginFailure $err) { $ok2 = FALSE; } assert($ok === $ok2); } /** * Check one of the values. We always assume that addrOwner should be able * to sign in, addrOther never, and addrSigner sometimes. * @param val The value to set the name to for this trial. * @param signerOk Whether addrSigner is allowed to sign in. */ function checkValue($val, $signerOk) { global $nc, $auth; global $name, $addrOwner, $sigOwner, $sigSigner, $sigOther; $nc->set($name, $addrOwner, $val); checkLogin($sigOwner, TRUE); checkLogin($sigSigner, $signerOk); checkLogin($sigOther, FALSE); checkLogin(base64_encode("invalid sig"), FALSE); } /* Perform the checks. */ checkValue("invalid-json", FALSE); checkValue("{\"email\": \"d@domob.eu\"}", FALSE); checkValue("{\"signer\": 42}", FALSE); checkValue("{\"signer\": \"{$addrSigner}\"}", TRUE); checkValue("{\"signer\": []}", FALSE); checkValue("{\"signer\": [\"{$addrSigner}\"]}", TRUE); checkValue("{\"signer\": [\"{$addrSigner}\", 42, \"invalid\", null]}", TRUE); $nc->close();