FreeAndFair / OpenRLA

Free & Fair's open source RLA support software.
Other
4 stars 3 forks source link

How to set election outcomes via curl #77

Closed nealmcb closed 7 years ago

nealmcb commented 7 years ago

I tried to record some UI actions in one election, then replay them in another. To do that I set up an election from backend/test/data/dominion/example/. I used View/Toggle Developer Tools and went to the Network tab in the Google Developer Tools. That records web traffic. I recorded setting some outcomes for the election, right-clicked on the "Name" area and chose "Copy All as HAR", pasted that to http://mattcg.github.io/har-to-curl/ and copied the resulting curl commands.

Then I made a fresh election, loaded the same manifests, and ran the following curl command, which seemed like a likely candidate:

curl -X POST -H "Origin: null" -H "Accept-Encoding: gzip, deflate" -H "Host: localhost:8080" -H "Accept-Language: en-US" -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.113 Electron/1.4.4 Safari/537.36" -H "content-type: text/plain;charset=UTF-8" -H "Accept: */*" -H "Connection: keep-alive" -H "Content-Length: 154" -d "{"id":1009,"shares":[{"id":10,"share":0.4},{"id":11,"share":0.3},{"id":12,"share":0.2},{"id":13,"share":0.05},{"id":14,"share":0.05},{"id":15,"share":0}]}" http://localhost:8080/election/1/outcome

It took a while, perhaps timed out, and said:

Something went wrong

I don't see any outcomes in the Outcomes tab either.

Any tips on how to figure out what the problem is? E.g. do I have to stop one client before running another one? Do I have to run some other curl commands to set things up?

ranweiler commented 7 years ago

Hmm, a few ideas:

  1. Based on what you said, you already did this, but just to be sure: the query you posted will fail unless an election with id == 1 exists and a bunch of preconditions are met. The preconditions include: the relevant contests and candidates are defined. Practically, this means that you will have needed to set an election title and date, then upload at least a contest and candidate manifest.
  2. Most state-mutating frontend actions have the following data flow: the frontend updates the backend state using an HTTP request, fetches a fresh copy of the state it may have changed/resources it has created, and transforms and merges the new state over its own state tree. That means that if you use curl to update backend state, the frontend will not see it unless it has had occasion to re-fetch the relevant backend state. If you are seeing an issue that is due to this, you can hit Ctrl-R/Cmd-R to refresh the application window (which is just a Chromium content pane), which will trigger an initial fetch against all relevant endpoints. Alternately, you can quit and re-open the frontend application.

I'm not sure exactly what would've triggered the "Something went wrong" error, but it is not one a custom error message.

Can you repro the failure? Does refreshing the application window fix it?

nealmcb commented 7 years ago

Aha - it seems that that har-to-curl web site doesn't properly retain the backslashes before the internal quotes. The proper curl commands (stripped of unneeded headers, but with made-up vote shares) for the two contested contests in that primary are:

curl -X POST -H  "Host: localhost:8080" -d "{\"id\":1009,\"shares\":[{\"id\":10,\"share\":0.4},{\"id\":11,\"share\":0.3},{\"id\":12,\"share\":0.2},{\"id\":13,\"share\":0.05},{\"id\":14,\"share\":0.05},{\"id\":15,\"share\":0}]}" http://localhost:8080/election/1/outcome

curl -X POST -H  "Host: localhost:8080" -d "{\"id\":1002,\"shares\":[{\"id\":2,\"share\":0.9},{\"id\":3,\"share\":0.1}]}" http://localhost:8080/election/1/outcome
nealmcb commented 7 years ago

FWIW, I reported the problem in that open source har-to-curl command: see https://github.com/mattcg/har-to-curl/issues/5

nealmcb commented 7 years ago

See an example of a full audit controlled via curl in the democontrol branch at https://github.com/FreeAndFair/OpenRLA/blob/democontrol/openrla-assistant/democontrol.sh