pusharmor 0.0.26__tar.gz → 0.0.28__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pusharmor
3
- Version: 0.0.26
3
+ Version: 0.0.28
4
4
  Summary: PushArmor command-line client
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://pusharmor.com
@@ -58,16 +58,7 @@ On Windows they live in `%APPDATA%\PushArmor` (or `%PUSHARMOR_CONFIG%`, or `--co
58
58
 
59
59
  ## Exit codes
60
60
 
61
- | Code | Meaning |
62
- | ---- | ------- |
63
- | 0 | success |
64
- | 1 | error: a failed request, a damaged or unreadable file, or a failed write on this device |
65
- | 2 | wrong command line, or the command needs a terminal |
66
- | 3 | not logged in, logged out, or this device was removed |
67
- | 4 | send failed for at least one device, or there is no device to send to |
68
- | 70 | an unexpected error in PushArmor; please report it |
69
- | 75 | the relay server is busy or unreachable; try again later |
70
- | 130 | stopped with Ctrl-C |
61
+ `pusharmor --help` lists the exit codes and their meaning.
71
62
 
72
63
  ## Needs
73
64
 
@@ -48,16 +48,7 @@ On Windows they live in `%APPDATA%\PushArmor` (or `%PUSHARMOR_CONFIG%`, or `--co
48
48
 
49
49
  ## Exit codes
50
50
 
51
- | Code | Meaning |
52
- | ---- | ------- |
53
- | 0 | success |
54
- | 1 | error: a failed request, a damaged or unreadable file, or a failed write on this device |
55
- | 2 | wrong command line, or the command needs a terminal |
56
- | 3 | not logged in, logged out, or this device was removed |
57
- | 4 | send failed for at least one device, or there is no device to send to |
58
- | 70 | an unexpected error in PushArmor; please report it |
59
- | 75 | the relay server is busy or unreachable; try again later |
60
- | 130 | stopped with Ctrl-C |
51
+ `pusharmor --help` lists the exit codes and their meaning.
61
52
 
62
53
  ## Needs
63
54
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pusharmor
3
- Version: 0.0.26
3
+ Version: 0.0.28
4
4
  Summary: PushArmor command-line client
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://pusharmor.com
@@ -58,16 +58,7 @@ On Windows they live in `%APPDATA%\PushArmor` (or `%PUSHARMOR_CONFIG%`, or `--co
58
58
 
59
59
  ## Exit codes
60
60
 
61
- | Code | Meaning |
62
- | ---- | ------- |
63
- | 0 | success |
64
- | 1 | error: a failed request, a damaged or unreadable file, or a failed write on this device |
65
- | 2 | wrong command line, or the command needs a terminal |
66
- | 3 | not logged in, logged out, or this device was removed |
67
- | 4 | send failed for at least one device, or there is no device to send to |
68
- | 70 | an unexpected error in PushArmor; please report it |
69
- | 75 | the relay server is busy or unreachable; try again later |
70
- | 130 | stopped with Ctrl-C |
61
+ `pusharmor --help` lists the exit codes and their meaning.
71
62
 
72
63
  ## Needs
73
64
 
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env python3
2
- # PushArmor command-line client, version 0.0.26
2
+ # PushArmor command-line client, version 0.0.28
3
3
  """PushArmor command-line client.
4
4
 
5
5
  The top part is the core layer: encodings, keys, signed requests, HPKE,
@@ -42,7 +42,7 @@ except BaseException: # missing, or broken: no _cffi_backend is ImportError, a
42
42
  sys.stderr.write("error: " + CRYPTO_MISSING + "\n")
43
43
  sys.exit(1)
44
44
 
45
- VERSION = "0.0.26"
45
+ VERSION = "0.0.28"
46
46
 
47
47
  # ---- encodings ----
48
48
 
@@ -2128,6 +2128,8 @@ def on_commit(cx, frm, c_n, listed):
2128
2128
  # the old entry is gone: decide the new commit on its own
2129
2129
  if dec["entry"].startswith("created") or dec["entry"] == "n_wiped_x_replied":
2130
2130
  e = d["pairs"][frm] = new_entry("X", "prompted", secrets.token_bytes(32), c_n)
2131
+ if p.get("ruling") == "denied": # a new request shows a rejected device again
2132
+ p["ruling"] = "none"
2131
2133
  e["authorized"] = dec["action"] == "reply"
2132
2134
  if dec["cap_counted"]:
2133
2135
  d["pair_auto"] = [t for t in d["pair_auto"] if 0 <= now - t < PAIR_CAP_WINDOW_S] + [now]
@@ -2195,6 +2197,15 @@ def post_pair(cx, x, kind, c):
2195
2197
  return j["r"] if isinstance(j.get("r"), str) else "failed"
2196
2198
 
2197
2199
 
2200
+ def could_not(err, verb, name):
2201
+ """The Fail for a confirm or reject that the relay server did not take (a 401 goes on to log in again)."""
2202
+ if isinstance(err, ApiError):
2203
+ if err.status == 401:
2204
+ return err
2205
+ return Fail('Could not %s "%s". %s' % (verb, name, err.reason()))
2206
+ return Fail('Could not %s "%s". %s' % (verb, name, err), err.code)
2207
+
2208
+
2198
2209
  def pair_reason(r, name):
2199
2210
  """A post_pair or post_approve result word -> reason; the word itself is never shown."""
2200
2211
  if r == "network":
@@ -2648,7 +2659,7 @@ def peer_status(p, e):
2648
2659
  return "waiting for it to confirm"
2649
2660
  if e:
2650
2661
  return "wants to pair" if e["role"] == "X" and e["state"] == "prompted" else "pairing"
2651
- return "rejected" if p["ruling"] == "denied" else "not paired"
2662
+ return "not paired"
2652
2663
 
2653
2664
 
2654
2665
  def pair_list(cx):
@@ -2657,6 +2668,8 @@ def pair_list(cx):
2657
2668
  ids = list(d["peers"]) + [cx.me]
2658
2669
  rows = [("ID", "NAME", "DEVICE", "STATUS"), (short_id(cx.me, ids), d["name"], "Command line", "this device")]
2659
2670
  for pid, p in sorted(d["peers"].items(), key=lambda kv: kv[1]["created"]):
2671
+ if p["ruling"] == "denied" and pid not in d["pairs"]:
2672
+ continue # rejected: hidden until it asks again or pair ID is run
2660
2673
  rows.append((short_id(pid, ids), peer_label(p), platform_label(p["platform"]),
2661
2674
  peer_status(p, d["pairs"].get(pid))))
2662
2675
  w = [max(len(r[i]) for r in rows) for i in range(3)]
@@ -2679,6 +2692,9 @@ def cmd_pair(cx, args):
2679
2692
  x = cx.target = resolve_peer(cx, args.id, with_self=True)
2680
2693
  if x == cx.me:
2681
2694
  raise Fail("This is the device you are using. Choose another device.")
2695
+ with cx.store.state() as d:
2696
+ if d["peers"][x]["ruling"] == "denied":
2697
+ d["peers"][x]["ruling"] = "none"
2682
2698
  with cx.store.state(write=False) as d:
2683
2699
  drain = Stream(d["ntfy"], d["topic"], cx.keys, d.get("since", ""), WAIT_TIMEOUT_S, poll=True)
2684
2700
  while True: # pairing messages the relay server sent while nothing listened
@@ -2712,12 +2728,18 @@ def cmd_pair(cx, args):
2712
2728
  print() # Ctrl-D leaves the cursor after the prompt
2713
2729
  raise Fail("No answer was given. Run pusharmor pair %s again." % sid)
2714
2730
  if not yes:
2715
- deny(cx, x)
2731
+ try:
2732
+ deny(cx, x)
2733
+ except (ApiError, TempFail) as err:
2734
+ raise could_not(err, "reject", name)
2716
2735
  print('Did not pair with "%s".' % name)
2717
2736
  return EXIT_OK
2718
- r = approve(cx, x)
2737
+ try:
2738
+ r = approve(cx, x)
2739
+ except (ApiError, TempFail) as err:
2740
+ raise could_not(err, "confirm", name)
2719
2741
  if r not in ("sent", "stored"):
2720
- raise Fail(pair_reason(r, name))
2742
+ raise Fail('Could not confirm "%s". %s' % (name, pair_reason(r, name)))
2721
2743
  continue
2722
2744
  if p["pinned"] and p["ruling"] == "approved":
2723
2745
  wait = 'Waiting for "%s" to confirm this device.' % name
@@ -2882,6 +2904,10 @@ def cmd_rename(cx, args):
2882
2904
  if not NAME_RE.fullmatch(args.name):
2883
2905
  raise Fail("The name must be 1 to 32 plain ASCII characters, with no double quote.", EXIT_USAGE)
2884
2906
  cx.need()
2907
+ with cx.store.state(write=False) as d:
2908
+ if d.get("name") == args.name:
2909
+ print('This device is already named "%s".' % args.name)
2910
+ return EXIT_OK
2885
2911
  k = cx.keys
2886
2912
 
2887
2913
  def content(pid, p, n, names):
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["setuptools>=77"]
2
+ requires = ["setuptools==84.1.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
@@ -558,7 +558,7 @@ def test_ctrl_d_at_the_fingerprint_prompt_keeps_the_pairing(net, tmp_path, monke
558
558
 
559
559
 
560
560
  def test_abort_in_shown_drops_the_pin_and_keeps_the_ruling(net, tmp_path, monkeypatch, capsys):
561
- """a different c_N while X shows the fingerprint drops the pin X made; the ruling stays."""
561
+ """a different c_N while X shows the fingerprint drops the pin X made."""
562
562
  a, b = tmp_path / "a", tmp_path / "b"
563
563
  ida, _ = login(monkeypatch, a), login(monkeypatch, b)
564
564
  cx = pa.Ctx(b)
@@ -572,10 +572,89 @@ def test_abort_in_shown_drops_the_pin_and_keeps_the_ruling(net, tmp_path, monkey
572
572
  pa.on_commit(cx, ida, b"d" * 32, "yes")
573
573
  p = state(b)["peers"][ida]
574
574
  assert state(b)["pairs"][ida]["c_N"] == pa.b64e(b"d" * 32)
575
- assert not p["pinned"] and p["pairing_id"] == "" and p["ruling"] == "denied"
575
+ assert not p["pinned"] and p["pairing_id"] == "" and p["ruling"] == "none" # the new request clears "denied"
576
576
  assert 'failed. Run: pusharmor pair %s to start again.' % pa.id_hex(ida)[:6] in capsys.readouterr().err
577
577
 
578
578
 
579
+ def pair_with_b_answer(monkeypatch, net, a, b, ida, idb, answer):
580
+ """a confirms; b gets the fingerprint prompt and gives `answer`. Returns b's exit code."""
581
+ monkeypatch.setattr(pa, "PAIR_WAIT_S", 8)
582
+
583
+ def inp(prompt=""):
584
+ return answer if threading.current_thread().name == "b" else "y"
585
+
586
+ monkeypatch.setattr(pa, "input", inp, raising=False)
587
+ codes = {}
588
+ before = net.count(idb)
589
+ ta = threading.Thread(target=lambda: codes.__setitem__("a", run(a, "pair", pa.id_hex(idb)[:6])), name="a")
590
+ ta.start()
591
+ end = time.time() + 10
592
+ while net.count(idb) == before and time.time() < end:
593
+ time.sleep(0.02)
594
+ tb = threading.Thread(target=lambda: codes.__setitem__("b", run(b, "pair", pa.id_hex(ida)[:8])), name="b")
595
+ tb.start()
596
+ tb.join(30)
597
+ ta.join(30)
598
+ return codes["b"]
599
+
600
+
601
+ def test_failed_reject_says_could_not_reject(net, tmp_path, monkeypatch, capsys):
602
+ a, b = tmp_path / "a", tmp_path / "b"
603
+ ida, idb = login(monkeypatch, a), login(monkeypatch, b)
604
+ net.hooks[("POST", "deny")] = lambda *x: net.reply(500, {})
605
+ capsys.readouterr()
606
+ assert pair_with_b_answer(monkeypatch, net, a, b, ida, idb, "n") == pa.EXIT_TEMP
607
+ name = pa.peer_label(state(b)["peers"][ida])
608
+ assert 'error: Could not reject "%s". %s' % (name, pa.SERVER_DOWN) in capsys.readouterr().err.splitlines()
609
+
610
+
611
+ def test_failed_confirm_says_could_not_confirm(net, tmp_path, monkeypatch, capsys):
612
+ a, b = tmp_path / "a", tmp_path / "b"
613
+ ida, idb = login(monkeypatch, a), login(monkeypatch, b)
614
+ net.hooks[("POST", "approve")] = lambda *x: net.reply(200, {"r": "denied"})
615
+ capsys.readouterr()
616
+ assert pair_with_b_answer(monkeypatch, net, a, b, ida, idb, "y") == 1
617
+ name = pa.peer_label(state(b)["peers"][ida])
618
+ assert 'error: Could not confirm "%s". "%s" is not paired with this device.' % (name, name) \
619
+ in capsys.readouterr().err.splitlines()
620
+
621
+
622
+ def test_rejected_device_is_hidden_until_it_asks_again_or_pair_id_runs(net, tmp_path, monkeypatch, capsys):
623
+ a, b = tmp_path / "a", tmp_path / "b"
624
+ ida, idb = login(monkeypatch, a), login(monkeypatch, b)
625
+ assert pair_with_b_answer(monkeypatch, net, a, b, ida, idb, "n") == 0
626
+ assert state(b)["peers"][ida]["ruling"] == "denied"
627
+ capsys.readouterr()
628
+ assert run(b, "pair") == 0
629
+ out = capsys.readouterr().out
630
+ assert pa.id_hex(ida)[:6] not in out and "rejected" not in out and "this device" in out
631
+ # pair ID still finds the hidden device and clears the denied state
632
+ monkeypatch.setattr(pa, "PAIR_WAIT_S", 1)
633
+ assert run(b, "pair", pa.id_hex(ida)[:8]) == 1
634
+ assert state(b)["peers"][ida]["ruling"] == "none"
635
+ capsys.readouterr()
636
+ assert run(b, "pair") == 0
637
+ assert pa.id_hex(ida)[:6] in capsys.readouterr().out
638
+
639
+
640
+ def test_incoming_request_shows_a_rejected_device_again(net, tmp_path, monkeypatch, capsys):
641
+ a, b = tmp_path / "a", tmp_path / "b"
642
+ ida, idb = login(monkeypatch, a), login(monkeypatch, b)
643
+ cx = pa.Ctx(b)
644
+ cx.setup()
645
+ cx.refresh()
646
+ with cx.store.state() as d:
647
+ d["peers"][ida]["ruling"] = "denied"
648
+ capsys.readouterr()
649
+ assert run(b, "pair") == 0
650
+ assert pa.id_hex(ida)[:6] not in capsys.readouterr().out
651
+ pa.on_commit(cx, ida, b"d" * 32, "yes")
652
+ assert state(b)["peers"][ida]["ruling"] == "none"
653
+ capsys.readouterr()
654
+ assert run(b, "pair") == 0
655
+ assert pa.id_hex(ida)[:6] in capsys.readouterr().out
656
+
657
+
579
658
  def test_abort_then_decides_the_new_commit(net, tmp_path, monkeypatch, capsys):
580
659
  """a different c_N ends the old X entry; the new commit is then decided, not dropped."""
581
660
  a, b = tmp_path / "a", tmp_path / "b"
@@ -1196,16 +1275,14 @@ def test_unusable_keys_are_one_line_and_kept(change, monkeypatch, tmp_path, net,
1196
1275
  assert state(cfg)["name"] != "stale" and state(cfg)["reg"] == "registered"
1197
1276
 
1198
1277
 
1199
- def test_help_and_readme_list_every_exit_code(capsys):
1278
+ def test_help_lists_every_exit_code(capsys):
1200
1279
  with pytest.raises(SystemExit) as e:
1201
1280
  pa.main(["--help"])
1202
1281
  assert e.value.code == 0
1203
1282
  out = capsys.readouterr().out
1204
- readme = open(os.path.join(os.path.dirname(HERE), "README.md"), encoding="utf-8").read()
1205
1283
  assert len(pa.EXIT_CODES) == 8
1206
1284
  for code, text in pa.EXIT_CODES:
1207
1285
  assert " %-3d %s" % (code, text) in out
1208
- assert "| %d | %s |" % (code, text) in readme
1209
1286
 
1210
1287
 
1211
1288
  # ---- crashes: every error is one line on stderr and a listed exit code ----
@@ -1809,6 +1886,28 @@ def test_listen_error_is_one_line_and_listening_continues(net, tmp_path, monkeyp
1809
1886
  assert "warning: " + pa.UNREACHABLE + " Listening continues." in err and not any("Unable" in x for x in err)
1810
1887
 
1811
1888
 
1889
+ def test_listen_ignores_a_check_push_silently(net, tmp_path, monkeypatch, capsys):
1890
+ a, b = tmp_path / "a", tmp_path / "b"
1891
+ ida, idb = pair_two(monkeypatch, net, a, b)
1892
+ net.deliver(idb, '{"check":1}')
1893
+ net.stop.set()
1894
+ capsys.readouterr()
1895
+ assert run(b, "listen") == 130
1896
+ cap = capsys.readouterr()
1897
+ assert cap.out == "" and cap.err.splitlines() == ["info: Listening. Press Ctrl+C to stop.", "info: Stopped."]
1898
+
1899
+
1900
+ def test_peers_list_with_my_relay_fault_is_accepted(net, tmp_path, monkeypatch, capsys):
1901
+ a, b = tmp_path / "a", tmp_path / "b"
1902
+ ida, idb = pair_two(monkeypatch, net, a, b)
1903
+ real = net.list_body
1904
+ monkeypatch.setattr(net, "list_body", lambda me: dict(real(me), my_relay_fault=True))
1905
+ capsys.readouterr()
1906
+ assert run(a, "pair") == 0
1907
+ cap = capsys.readouterr()
1908
+ assert pa.id_hex(idb)[:6] in cap.out and cap.err == ""
1909
+
1910
+
1812
1911
  def test_command_texts_are_the_approved_sentences(net, tmp_path, monkeypatch, capsys):
1813
1912
  def err_of(code, *argv):
1814
1913
  capsys.readouterr()
@@ -1878,3 +1977,14 @@ def test_login_link_too_old_says_the_code_expired(net, tmp_path, monkeypatch, ca
1878
1977
  assert run(tmp_path, "login") == 1
1879
1978
  out = capsys.readouterr().out
1880
1979
  assert "The code expired. Open the link to get a new code:\n\n %s/auth/cli#" % pa.SITE in out
1980
+
1981
+
1982
+ def test_rename_to_the_same_name_makes_no_network_call(net, tmp_path, monkeypatch, capsys):
1983
+ a = tmp_path / "a"
1984
+ login(monkeypatch, a)
1985
+ name = state(a)["name"]
1986
+ capsys.readouterr()
1987
+ before = len(net.log)
1988
+ assert run(a, "rename", name) == 0
1989
+ assert capsys.readouterr().out == 'This device is already named "%s".\n' % name
1990
+ assert len(net.log) == before and state(a)["name"] == name
File without changes