Skip to content

FIX: Redeem a sealed Human Confidence value in the cloud request engine - #274

Draft
jwrosewell wants to merge 1 commit into
feature/humanconfidence-web-demofrom
feature/hc-package-redeem
Draft

jwrosewell wants to merge 1 commit into
feature/humanconfidence-web-demofrom
feature/hc-package-redeem

Conversation

@jwrosewell

Copy link
Copy Markdown
Contributor

Why

The draft Human Confidence specification (51Degrees/specifications#201) says the language package redeems a sealed value through the JSON call its Cloud Request Engine already makes, and that an example MUST NOT redeem one itself. This does both for Python.

It is opened against the branch of #271, the web demo it changes, so it shows only its own change. Merge #271 first.

What changes

Package

  • New module humanconfidence.py with HumanConfidenceNames, every name used in one place, and HumanConfidenceChallenges, an in-memory store that gives each page a new random page value and challenge, gives each out once, drops them after 60 seconds, and keeps at most 100,000, oldest dropped first.
  • CloudRequestEngine:
    • human_confidence_page_values() gives a page {"challenge": ..., "humanconfidencepage": ...}. The new setting human_confidence_challenges takes another store with issue and take, such as one shared between servers.
    • A request with a non-empty query.humanconfidence takes the challenge kept for query.humanconfidencepage. The JSON call, to the same endpoint as before, sends humanconfidence as it arrived, challenge (the one kept), license, and values with derived.humanconfidence added for that call only. Evidence whose name strips to challenge or humanconfidence is left out, under any prefix and in any letter case, and humanconfidencepage is never sent.
    • The answer's derived section gets humanconfidence as the level, or Low, and humanconfidencesource as Active. With no License Key, no challenge kept for the page, no call made, or a failed call, the data is still set to Low and Active. A failed call is then raised, so it is the engine's error as on any other request.
    • Such a request is neither served from nor stored in the cache.
    • Messages built from such a request show the sealed value, the challenge, and the License Key as ********. Other requests keep the masking they have today.
    • process sets the cloud-response alias in a finally block, so it is set even when the engine raises after setting its data.
  • A consumer reads derived.humanconfidence and derived.humanconfidencesource through a CloudEngine with datakey = "derived", as this package already does for other sections. No new element is added.

Web demo

  • The /redeem route and its call to hc/redeem are gone.
  • A second pipeline, whose engine carries the License Key and is built from the first engine's discovery, gives each page load its values and redeems, with process exceptions suppressed. Building the app asks the cloud nothing more.
  • The page asks for the 51Degrees script with ?challenge= in both modes, and sends the first sealed value to /active as humanconfidence, with humanconfidencepage. /active gives only humanConfidence and humanConfidenceSource, and a value that does not redeem gives Active Low.
  • The replay command posts to /active in the same way. The page value is used once, so a replay after the page has redeemed gives Active Low.
  • The example still writes nothing to the console after it starts, and a test covers /active.

Tests

  • Engine, from pipeline/fiftyone_pipeline_cloudrequestengine, python -m pytest tests. Before, 139 passed and 4 skipped. After, 164 passed and 6 skipped, the 6 being live tests with no key set. With the engine change taken out and the tests kept, every test of a sealed request fails.
  • tests/test_human_confidence.py follows the "Required tests" of the specification page case by case. The case "The Pipeline has no Cloud Request Engine" is not covered, as nothing in this package runs without one.
  • tests/test_human_confidence_live.py needs _51DEGREES_RESOURCE_KEY_BESPOKE and _51DEGREES_LICENSE_KEY_BESPOKE, uses _51DEGREES_CLOUD_ENDPOINT when it is set, and is marked live. It was not run.
  • Example, the three Human Confidence test files from pipeline/fiftyone_pipeline_cloudrequestengine/examples. Before, 88 passed and 4 skipped. After, 92 passed and 5 skipped, with no warnings under -W default. With the earlier app.py and index.html, every new /active, challenge, and script test fails.
  • To run the engine tests locally, parameterized (declared in tox.ini) and the js_templates submodule are needed.

Before this leaves draft

  1. Nothing has been run against a real cloud. Still to show are that a real sealed value redeems through the JSON call, that the answer carries the level in derived.humanconfidence, and that the client script carries ?challenge= into the call that seals the value. If it does not, every real redeem gives Low.
  2. The page's JavaScript has not been run in a browser.
  3. humanconfidencepage is a name this package chose, as the specification does not name one yet. The names in HumanConfidenceNames and human_confidence_page_values should be agreed before other languages follow them.
  4. The specification is still a draft, with open points on the challenge. The module docstring links to the page on main, which works once that pull request merges.
  5. Two docstrings say "licence key" where "License Key" is meant.

A request whose evidence holds a non-empty query.humanconfidence carries
a sealed value. The cloud request engine redeems it in the JSON call it
already makes, sending the value, the challenge it kept for the page,
and the License Key, and asking for derived.humanconfidence. Other
challenge evidence is left out. The answer gives the level and Active,
or Low and Active where the value is not redeemed. Such a request skips
the cache, and messages built from it show the three values as
asterisks.

human_confidence_page_values() gives each page a challenge and a page
value. HumanConfidenceChallenges keeps them for 60 seconds and gives
each out once, unless the human_confidence_challenges setting names
another store.

The web demo now redeems through a second pipeline whose engine has the
License Key. /active takes the place of /redeem, and the page asks for
the 51Degrees script with the challenge.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant