Repository navigation
Send the sealed result and transaction, and read status and Human Confidence, in the 51Did client - #286
Conversation
…fidence, in the 51Did client The cloud's 51Did endpoints now take sealedResult and transaction, and answer with status and the Human Confidence Value a 51Did carries. The old names keep working. DidClient.redeem takes sealed_result and transaction and sends them to the cloud under those names. The result and challenge arguments still work, with a DeprecationWarning naming the replacement, and the new names win when both are given. RedeemResult reads status into the new RedeemStatus enumeration, and reads humanConfidence into the new HumanConfidenceValue enumeration (High, Medium, Low or Absent), with the cloud's reason where it leaves the Value out. A cloud that sends no status has the status read from context, where it writes the failure word. to_dict is unchanged, so the Value never reaches a page through it. The EXPIRED, REPLAYED, UNREADABLE and UNCONFIRMED members of ContextResult are obsolete and give a DeprecationWarning when read by name. They keep their values, because the cloud still writes those words to context. verify is unchanged. The new verify_detailed makes the same call with the licence key in the X-51D-License-Key header, never in the URL, and reads the Value the cloud adds for a 51Did whose signature verifies. Tests check that every member reads each new answer exactly as it reads today's, with status, humanConfidence and obsolete present, and cover the new members and arguments.
The redeem request now sends the sealed result as both sealedResult and result, and the transaction as both transaction and challenge, with the same values. A cloud that reads only the obsolete names keeps working, and one that reads both takes the new names and adds an obsolete array, which the client ignores. A caller's own use of the result and challenge arguments still warns. The tests that pin the redeem request's field names now expect all four.
…ample The cloud's hc/redeem now reads the sealed result from sealedResult and answers with status, giving Medium as the level whenever status isn't success. The example now works with both that cloud and one that reads only value. The server sends the sealed result as both sealedResult and value, with the same text. It reads it from the page's sealedResult field, or from value as before. The page reads status first and falls back to result. It shows the level as redeemed only when status is success, or, where there's no status, when the cloud gave a level. The second redeem shows the status rather than the Medium level that comes with it. The offline test stand-in now answers as the new cloud does, and the tests expect both field names and cover the page sending value and an unconfirmed status being relayed.
| sealed = request.form.get("sealedResult") or request.form.get("value", "") | ||
| # The sealed result goes to the cloud as sealedResult, and as value | ||
| # too, with the same text, for a cloud that reads only value. | ||
| fields = {"sealedResult": sealed, "value": sealed} |
There was a problem hiding this comment.
Should fix The web example returns the licensed active Human Confidence value to the browser. The example redeems with the publisher's License Key and sends the service response back to the page, including the active humanConfidence value. Keep that value in the server handler and return only the application decision or status. Test the browser-facing JSON for absence of the value. If displaying the value is essential for diagnostics, restrict that display to an explicitly enabled local mode. app.py:223
There was a problem hiding this comment.
Not changing: this example's purpose is to show the redeemed Value. It did so before this change, and its comments say the publisher's server decides what to do with it.
There was a problem hiding this comment.
Agreed. The example sent the Value to the page before this change, and its comments leave the decision to the publisher's server, so it's out of scope here.
There was a problem hiding this comment.
Thanks. The example stays as it is.
| // that gives no status gives a level only on success. | ||
| function redeemed(answer) { | ||
| return answer.status ? answer.status === "success" | ||
| : Boolean(answer.humanConfidence); |
There was a problem hiding this comment.
Should fix The example displays a 4.4.55 replay or expiry as a successful redemption. Version 4.4.55 returns both humanConfidence="Low" and result="replayed" or "expired". This predicate tests only the presence of humanConfidence when status is missing. Read result before inferring success from the value and test both legacy failure bodies. index.html:156
There was a problem hiding this comment.
Fixed in 5e4b222: on an answer without status, the page now shows the level as redeemed only when result is left out or says success. expired, replayed, unreadable, unconfirmed and any other word are failures. A new test runs the page's check in Node against the current answers and the ones without status, both legacy failure bodies included.
There was a problem hiding this comment.
Verified. Without status, redeemed() now needs result (or context) to be missing or success, so the legacy expired and replayed bodies read as failures, and the new test runs the page check on both bodies.
| #: good one. A cloud that sends no ``status`` writes the same word | ||
| #: to ``context`` on every other outcome, so the status is then read | ||
| #: from ``context``. | ||
| self.status = _status_of(status, context) |
There was a problem hiding this comment.
Should fix The redemption parser lets the body override HTTP 503 instead of reporting Unconfirmed. The response contract makes HTTP 503 authoritative regardless of its body. This mapping can return Success for a 503 carrying a success-shaped object. Handle 503 before parsing the verdict and test an empty body, a non-JSON body and a conflicting status. did_client.py:495
There was a problem hiding this comment.
Fixed in 56ee07d: HTTP 503 is now always RedeemStatus.UNCONFIRMED with an unconfirmed context, and nothing else is read from the body. Tests cover an empty body, a body that isn't JSON, and a body that says success.
There was a problem hiding this comment.
Verified. from_response turns a non-object 503 body into an empty dict, and __init__ sets an unconfirmed status and context and clears the parsed body before the Value, signature, factors and times are read.
There was a problem hiding this comment.
Thanks. In 068c721 the rule moved into one branch in from_response, so __init__ no longer checks the status. A 503 now reads unconfirmed in status_raw as well as in context.
| for member in HumanConfidenceValue: | ||
| if member.value.lower() == value.lower(): | ||
| return member | ||
| return None |
There was a problem hiding this comment.
Should fix The typed reader conflates an unfamiliar Human Confidence word with an omitted field. The package contract assigns Absent to an unfamiliar word and reserves an omitted value for an answer without the field. Preserve the original word for diagnostics, return the named Absent value for an unfamiliar string, and test it separately from a missing field on verify and redeem. did_client.py:626
There was a problem hiding this comment.
Fixed in 56ee07d: an unknown humanConfidence word now reads as HumanConfidenceValue.ABSENT on verify and redeem, and the new RedeemResult.human_confidence_raw keeps the word as sent. A missing or null field reads as None, with the null reason where there is one. Tests cover both cases on verify and redeem.
There was a problem hiding this comment.
Verified. _human_confidence_of returns None only for None and ABSENT for any other value, on verify and redeem, and human_confidence_raw keeps a string word on redeem.
There was a problem hiding this comment.
Thanks. In 068c721 verify keeps the word too, as CloudVerification.human_confidence_raw, read by the same helper as redeem.
…Absent A redeem answer with HTTP 503 is now always the unconfirmed status, with an unconfirmed context, whatever its body says. An empty body or one that isn't JSON no longer raises, and nothing else is read from the body, so a 503 shaped like a redeemed result gives no verdict. A humanConfidence field holding a word this package doesn't know now reads as Absent on verify and redeem, so it's never taken for High, Medium or Low. A missing or null field still reads as None, with the null reason where the cloud gave one. RedeemResult keeps the word as sent in the new human_confidence_raw member.
A cloud that sends no status gives a level with expired and replayed, and names the outcome in result. The page now shows the level as redeemed only when result is left out or says success. Any other word is a failure. A new test runs the page's own check in Node against the current answers and the ones without status, failures included.
Jamesr51d
left a comment
There was a problem hiding this comment.
Thanks for the review. Each finding:
app.py:223: Not changing: this example's purpose is to show the redeemed Value. It did so before this change, and its comments say the publisher's server decides what to do with it.templates/index.html:156: Fixed in 5e4b222: on an answer withoutstatus, the page now shows the level as redeemed only whenresultis left out or sayssuccess.expired,replayed,unreadable,unconfirmedand any other word are failures. A new test runs the page's check in Node against the current answers and the ones withoutstatus, both legacy failure bodies included.did_client.py:495: Fixed in 56ee07d: HTTP 503 is now alwaysRedeemStatus.UNCONFIRMEDwith anunconfirmedcontext, and nothing else is read from the body. Tests cover an empty body, a body that isn't JSON, and a body that says success.did_client.py:626: Fixed in 56ee07d: an unknownhumanConfidenceword now reads asHumanConfidenceValue.ABSENTon verify and redeem, and the newRedeemResult.human_confidence_rawkeeps the word as sent. A missing or null field reads asNone, with the null reason where there is one. Tests cover both cases on verify and redeem.
Jamesr51d
left a comment
There was a problem hiding this comment.
Second pass: new findings.
| parsed = _try_parse_json(body) | ||
| if isinstance(parsed, dict): | ||
| valid = parsed.get("valid") | ||
| if isinstance(valid, bool): |
There was a problem hiding this comment.
Should fix _verify takes valid, and now the Human Confidence Value, from a JSON body on any HTTP status. A 403, 500 or 503 whose body holds {"valid": true, "humanConfidence": "High"} is returned by verify and verify_detailed as a valid signature with that Value. Accept valid only on a 200, read a 400 only as invalid, and raise DidClientError for every other status. Test valid: true on statuses other than 200.
There was a problem hiding this comment.
Fixed in 068c721: verify now reads valid and the Human Confidence fields only from an HTTP 200 answer. A 400 is invalid whatever its body says, and any other status raises DidClientError. A new test sends valid: true with a Value on 400, 201, 403, 404, 500 and 503 through both verify and verify_detailed.
| self.raw = raw | ||
| # HTTP 503 means first use could not be confirmed, whatever the | ||
| # body says, so no verdict is read from the body of one. | ||
| unconfirmed = status_code == 503 |
There was a problem hiding this comment.
Consider The Human Confidence fields are read twice, inline in _verify and here in RedeemResult.__init__, and only the redeem side keeps the raw word. A module-level helper returning the Value, the raw word and the null reason would serve both. The 503 rule is also split between from_response and __init__; one branch in from_response that builds the unconfirmed result would keep it in one place.
There was a problem hiding this comment.
Fixed in 068c721: _human_confidence_fields reads the Value, the raw word and the null reason for both verify and redeem, so CloudVerification now has human_confidence_raw too. The 503 rule is one branch in from_response, and __init__ no longer looks at the status. A test sends a 503 body claiming success with a signature, factors, times, a Value and a null reason, and every field reads empty.
Verify now reads valid and the Human Confidence fields only from an HTTP 200 answer. An HTTP 400 answer is invalid whatever its body says, and any other status raises DidClientError. RedeemResult.from_response now handles HTTP 503 on its own. The result is unconfirmed in status and context, and nothing else is read from the body. Verify and redeem read the Value, the raw word and the null reason through one helper. CloudVerification gains human_confidence_raw.
Jamesr51d
left a comment
There was a problem hiding this comment.
Round 2 answers.
did_client.py:886: Fixed in 068c721: verify readsvalidand the Human Confidence fields only from an HTTP 200 answer. A 400 is invalid whatever its body says, and any other status raisesDidClientError. A new test sendsvalid: truewith a Value on 400, 201, 403, 404, 500 and 503, through bothverifyandverify_detailed.did_client.py:476: Fixed in 068c721: one helper,_human_confidence_fields, now reads the Value, the raw word and the null reason for both verify and redeem, soCloudVerificationgainshuman_confidence_raw. A test checks that both read the same fields the same way. The 503 rule is now one branch inRedeemResult.from_response: status and context areunconfirmedand nothing else is read from the body. A test sends a 503 body that claims success with a signature, factors, times, a Value and a null reason, and checks every field is empty.
|
notcheckable, or any other word, comes back unreadable.
If it isn't a JSON object, or has no status and no context, status and context are unreadable and the signature is unknown.
The transaction argument of redeem now defaults to the same not-given marker as the others, so redeem(..., transaction=None, challenge="x") sends an empty transaction, as the docs say the new argument wins. challenge is used only when transaction is not given.
If query.humanconfidence holds a sealed value, the engine sends it with the page's transaction on its JSON call and returns what the cloud redeemed, or Medium when it didn't. Those calls skip the cache.
It no longer calls hc/redeem. The page posts to /humanconfidence and the server reads the two properties.
Where the server's answer holds no humanConfidence, the page now shows humanConfidenceNullReason in its place, as for any other property with no value, rather than passing an empty level to the display.
pylint flags it as assignment-from-none. process_internal returns nothing, so the sealed path returns None, same as the base engine on a cache miss.
A sealed value under a header, a cookie, server. or no prefix isn't sent, and neither are transaction or challenge.
Same for query.humanconfidencepage.
issue() is the only public method now.
Messages and the example page used to keep its last four characters.
Only discovery calls fail in the mock now, so a request for the flow data reaches the stand-in and gets recorded.
A sealed request then gets Medium and Active with no error.
The derived property element can't redeem a sealed Human Confidence result, but it still gave the High or Low its script worked out. On a request with a non-empty query.humanconfidence, an element that writes HumanConfidence now gives Medium and adds HumanConfidenceSource Active. Other requests are unchanged.
A 404 from redeem now says which URL does not offer the creator context, as the specification asks.
Anything else the cloud sends gives no value and a reason, or Medium on a sealed request.
Say that naming HumanConfidence delays the client script's complete handlers, and list what a page's Content Security Policy must allow for the browser tests.
is_blank() follows .NET's Char.IsWhiteSpace, which is what the cloud checks. A blank value is dropped from the call and the page's transaction stays kept.
The derived property element now ignores a query.humanconfidence that is empty or only white space, using the same white space test as the Cloud Request Engine.
Adds _hidden() and uses it for verify and redeem error messages and bodies. Tests added.
Source after a redeem is whatever the cloud says (Passive/Active), we don't hardcode Active any more. Not redeemed -> Medium, no source. New HumanConfidenceClient in fiftyone_pipeline_did for hc/redeem outside a pipeline. No redirects followed anywhere we call the cloud. Example page always posts the sealed result back. 51Did client takes license_key, old licence_key kept with a deprecation warning. Live tests updated for the new sealing on staging. Co-authored-by: Ben Shillito <ben@51degrees.com>
Brings in #290, which runs the 51Did and Human Confidence cloud tests against the staging cloud, and #281, #282 and #288. Two test files conflicted, and both keep the tests rc runs on staging. - pipeline/fiftyone_pipeline_did/tests/test_did_client_live.py: the browser creator context test names the 51Did Properties on the page's Resource Key call, as this branch does. Where that first answer carries no 51Did because the call requested HumanConfidence and was handed the browser tests, it asks with the licence key alone, as rc does. Any other answer without a 51Did still fails. The client test's own call is rc's, which gets its 51Did on staging. - pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/ test_cloud_humanconfidence_web.py: rc's tests, with is_sealed using the package's is_blank, so a blank value is never a sealed result. Run locally on Python 3.12 with no keys: fiftyone_pipeline_did 343 passed and 8 skipped, the cloud request engine examples 99 passed and 32 skipped. The live and staging tests skip without keys, so the Cloud 51Did and Cloud Human Confidence checks prove them.
…it is Step 1 of the web example asks the cloud with the Resource Key alone, which is the browser's route, so the cloud seals HumanConfidence. The page still printed that sealed text in the Human Confidence column as if it were a level. The page now shows a level when it gets one and otherwise says it got a sealed value, and the row and comments say which key the call uses. Only a License Key valid for Human Confidence with the visitor's ja4, h2 and client-ip gets a level on the first call, and this example doesn't make that call. The example also pointed to a readme.md beside it that doesn't exist, so that line is gone. Tests cover both.
|
Merged into rc for the 4.6.2 release. In Pull Requests run 46510716909 at 6403250, the only failing check is the cloud available properties test, which fails in all ten build and test jobs because the CI resource key does not yet include the new ServiceWorkers property. Every other test passed. |
Closes #285
What changed
DidClient.redeem(fod_id, sealed_result, transaction)sends the values assealedResultandtransaction, and also asresultandchallenge. Positional calls work as before.resultandchallenge, as production does today, so this release doesn't have to wait for the cloud. A cloud that reads both takes the new names and adds anobsoletearray to its answer, which the client ignores.RedeemResult.statusreadsstatusinto the newRedeemStatusenumeration (SUCCESS,EXPIRED,REPLAYED,UNCONFIRMEDandUNREADABLE), andstatus_rawkeeps the word as sent. A cloud that sends nostatushas it read fromcontext, where it writes the failure word.RedeemResult.human_confidencereadshumanConfidenceinto the newHumanConfidenceValueenumeration (HIGH,MEDIUM,LOWandABSENT).human_confidence_null_reasonholds the cloud's reason where it leaves the Value out.DidClient.verify_detailedmakes the verify call with the licence key in theX-51D-License-Keyheader, never in the URL, and answers aCloudVerificationwithvalid,human_confidenceandhuman_confidence_null_reason.hc/redeemas bothsealedResultandvalue, so it works with the new cloud and with production. Its page readsstatusfirst and falls back toresult, and shows the level as redeemed only onsuccess, because the new cloud gives Medium with every other status.What stays obsolete and working
resultandchallengearguments ofredeemstill work, with aDeprecationWarningnaming the replacement. The new names win when both are given.ContextResult.EXPIRED,REPLAYED,UNREADABLEandUNCONFIRMEDgive aDeprecationWarningwhen read by name. They keep their values, because the cloud still writes those words tocontext. Reading a member by value, as the package does, gives no warning.verifyis unchanged. It still answers a bool and sends no licence key.to_dictis unchanged, so neitherstatusnor the Value reaches a page through it.Left as they are
These published names have Result in them and aren't renamed or given replacements in this change:
RedeemResult,ContextResult,SignatureResult,FactorResultandFodIdParseResult.Tests
status,humanConfidence,humanConfidenceNullReasonandobsoletepresent, read exactly as today's answers do in every member a caller had before.ContextResultmembers, andverify_detailed. HTTP is mocked, as the existing client tests do.pytest -m "not live") give 304 passed and 8 deselected, up from 270 passed onrc. The only change to existing tests is the field names they expect in the redeem request, which are now all four.