Skip to content

Commit 30fe214

Browse files
committed
Added some tests using a given signing key seed
1 parent bf9abd2 commit 30fe214

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

tests/test_known_key.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2015 OpenMarket Ltd
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import unittest
18+
19+
from unpaddedbase64 import decode_base64
20+
21+
import nacl.signing
22+
23+
from signedjson.sign import sign_json
24+
25+
SIGNING_KEY_SEED = decode_base64(
26+
"YJDBA9Xnr2sVqXD9Vj7XVUnmFZcZrlw8Md7kMW+3XA1"
27+
)
28+
29+
KEY_ALG = "ed25519"
30+
KEY_VER = 1
31+
KEY_NAME = "%s:%d" % (KEY_ALG, KEY_VER)
32+
33+
34+
class KnownKeyTestCase(unittest.TestCase):
35+
""" An entirely deterministic test using a given signing key seed, so that
36+
other implementations can compare that they get the same result. """
37+
38+
def setUp(self):
39+
self.signing_key = nacl.signing.SigningKey(SIGNING_KEY_SEED)
40+
self.signing_key.alg = KEY_ALG
41+
self.signing_key.version = KEY_VER
42+
43+
def test_sign_minimal(self):
44+
self.assertEquals(
45+
sign_json({}, "name", self.signing_key),
46+
{
47+
'signatures': {
48+
'name': {
49+
KEY_NAME: "K8280/U9SSy9IVtjBuVeLr+HpOB4BQFWbg+UZaADMt"
50+
"TdGYI7Geitb76LTrr5QV/7Xg4ahLwYGYZzuHGZKM5ZAQ"
51+
},
52+
}
53+
}
54+
)
55+
56+
def test_sign_with_data(self):
57+
self.assertEquals(
58+
sign_json({'one': 1, 'two': "Two"}, "name", self.signing_key),
59+
{
60+
'one': 1,
61+
'two': "Two",
62+
'signatures': {
63+
'name': {
64+
KEY_NAME: "KqmLSbO39/Bzb0QIYE82zqLwsA+PDzYIpIRA2sRQ4s"
65+
"L53+sN6/fpNSoqE7BP7vBZhG6kYdD13EIMJpvhJI+6Bw"
66+
},
67+
}
68+
}
69+
)

0 commit comments

Comments
 (0)