Tests for Pigeon::KeyPair
This commit is contained in:
parent
ede03bf5c4
commit
e3ac894ac2
|
@ -21,9 +21,10 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`.
|
|||
- [X] pigeon peer remove
|
||||
- [X] pigeon peer block
|
||||
- [X] pigeon peer all
|
||||
- [ ] Update spec to look [like this](https://gist.github.com/RickCarlino/3ff4178db4a75fd135832c403cd313d4)
|
||||
- [ ] pigeon message new
|
||||
- [ ] pigeon message current
|
||||
- [ ] pigeon message append
|
||||
- [ ] pigeon message current
|
||||
- [ ] pigeon message save
|
||||
- [ ] pigeon message find
|
||||
- [ ] pigeon message find-all
|
||||
|
|
17
TODO.md
17
TODO.md
|
@ -2,9 +2,24 @@ I need to implement these.
|
|||
|
||||
I'm adding them here for quick reference.
|
||||
|
||||
```
|
||||
author @ajgdylxeifojlxpbmen3exlnsbx8buspsjh37b/ipvi=.ed25519
|
||||
depth 23
|
||||
kind "example"
|
||||
prev %85738f8f9a7f1b04b5329c590ebcb9e425925c6d0984089c43a022de4f19c281.sha256
|
||||
|
||||
"foo":&3f79bb7b435b05321651daefd374cdc681dc06faa65e374e38337b88ca046dea.sha256
|
||||
"baz":"bar"
|
||||
"my_friend":@abcdef1234567890.ed25519
|
||||
"really_cool_message":%85738f8f9a7f1b04b5329c590ebcb9e425925c6d0984089c43a022de4f19c281.sha256
|
||||
"baz":"whatever"
|
||||
|
||||
signature "3er8...LOgRdrGnuihBp4QYWYPJ5bS1Gw9weQKj9DQ==.sig.ed25519"
|
||||
```
|
||||
|
||||
```bash
|
||||
pigeon message new my_message
|
||||
# => "Switched to message `my_message`
|
||||
# => "Switched to message (kind: `my_message`)
|
||||
|
||||
pigeon message current # Show active log entry.
|
||||
# => author: @ajgdylxeifojlxpbmen3exlnsbx8buspsjh37b/ipvi=.ed25519
|
||||
|
|
|
@ -5,10 +5,6 @@ module Pigeon
|
|||
class KeyPair
|
||||
HEADER, FOOTER = ["@", ".ed25519"]
|
||||
|
||||
def self.current
|
||||
raise "TODO"
|
||||
end
|
||||
|
||||
def self.strip_headers(identity)
|
||||
identity.sub(HEADER, "").sub(FOOTER, "")
|
||||
end
|
||||
|
@ -35,12 +31,15 @@ module Pigeon
|
|||
@public_key ||= KeyPair.add_headers(b64)
|
||||
end
|
||||
|
||||
def save!
|
||||
Storage.current.add_peer(public_key)
|
||||
def to_h
|
||||
{
|
||||
public_key: public_key,
|
||||
private_key: private_key,
|
||||
}.map do |k, v|
|
||||
}
|
||||
end
|
||||
|
||||
def save!
|
||||
self.to_h.map do |k, v|
|
||||
Pigeon::Storage.current.set_conf(k, v)
|
||||
end
|
||||
end
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"previous": null,
|
||||
"author": "@z2M8msI2EUubNHnrEJncglDIy2/SUd+36jCyJnfeiHk=.ed25519",
|
||||
"sequence": 1,
|
||||
"timestamp": 1554164725521,
|
||||
"hash": "sha256",
|
||||
"content": {
|
||||
"type": "about",
|
||||
"about": "@z2M8msI2EUubNHnrEJncglDIy2/SUd+36jCyJnfeiHk=.ed25519",
|
||||
"image": "&jqMB109+asDMUVWkeAsqK/4KlbF+6M2x+jtTdFIdVw8=.sha256",
|
||||
"name": "Netscape Navigator"
|
||||
},
|
||||
"signature": "3er8E88P7WPSjnm+L3QmoPqNxhqAn/pOjvo6Owk0KNn69FgOjAYLOgRdrGnuihBp4QYWYPJ5bS1Gw9weQKj9DQ==.sig.ed25519"
|
||||
}
|
|
@ -4,7 +4,10 @@ RSpec.describe Pigeon::KeyPair do
|
|||
FAKE_SEED = "\x15\xB1\xA8\x1D\xE1\x1Cx\xF0" \
|
||||
"\xC6\xDCK\xDE\x9A\xB7>\x86o\x92\xEF\xB7\x17" \
|
||||
")\xFF\x01E\b$b)\xC9\x82\b"
|
||||
|
||||
TO_H = {
|
||||
private_key: "FbGoHeEcePDG3Evemrc-hm-S77cXKf8BRQgkYinJggg=",
|
||||
public_key: "@7n_g0ca9FFWvMkXy2TMwM7bdMn6tNiEHKzrFX-CzAmQ=.ed25519",
|
||||
}
|
||||
let(:kp) { Pigeon::KeyPair.new(FAKE_SEED) }
|
||||
|
||||
it "generates a pair from a seed" do
|
||||
|
@ -14,6 +17,25 @@ RSpec.describe Pigeon::KeyPair do
|
|||
expect(kp.private_key).to eq(y)
|
||||
end
|
||||
|
||||
# TODO Add fakefs https://github.com/fakefs/fakefss
|
||||
it "saves keypairs to disk"
|
||||
it "strips headers" do
|
||||
whatever = "af697f3063d46fe9546f651c08c378f8"
|
||||
example = [
|
||||
Pigeon::KeyPair::HEADER,
|
||||
whatever,
|
||||
Pigeon::KeyPair::FOOTER,
|
||||
].join("")
|
||||
result = Pigeon::KeyPair.strip_headers(example)
|
||||
expect(result).to eq(whatever)
|
||||
end
|
||||
|
||||
it "converts to a Hash" do
|
||||
expect(kp.to_h).to eq(TO_H)
|
||||
end
|
||||
|
||||
it "saves to disk" do
|
||||
TO_H.to_a.map do |pair|
|
||||
expect(Pigeon::Storage.current).to receive(:set_conf).with(*pair)
|
||||
end
|
||||
kp.save!
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue