Python tornado.web 模块,create_signed_value() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用tornado.web.create_signed_value()

项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_types(self):
        cookie_value = to_unicode(create_signed_value(self.COOKIE_SECRET,
                                                      "asdf", "qwer"))
        response = self.fetch("/typecheck/asdf?foo=bar",
                              headers={"Cookie": "asdf=" + cookie_value})
        data = json_decode(response.body)
        self.assertEqual(data, {})

        response = self.fetch("/typecheck/asdf?foo=bar", method="POST",
                              headers={"Cookie": "asdf=" + cookie_value},
                              body="foo=bar")
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_known_values(self):
        signed_v1 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=1, clock=self.present)
        self.assertEqual(
            signed_v1,
            b"dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4f")

        signed_v2 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=2, clock=self.present)
        self.assertEqual(
            signed_v2,
            b"2|1:0|10:1300000000|3:key|8:dmFsdWU=|"
            b"3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152")

        signed_default = create_signed_value(SignedValueTest.SECRET,
                                             "key", "value", clock=self.present)
        self.assertEqual(signed_default, signed_v2)

        decoded_v1 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v1, min_version=1,
                                         clock=self.present)
        self.assertEqual(decoded_v1, b"value")

        decoded_v2 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v2, min_version=2,
                                         clock=self.present)
        self.assertEqual(decoded_v2, b"value")
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_name_swap(self):
        signed1 = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                      clock=self.present)
        signed2 = create_signed_value(SignedValueTest.SECRET, "key2", "value",
                                      clock=self.present)
        # Try decoding each string with the other's "name"
        decoded1 = decode_signed_value(SignedValueTest.SECRET, "key2", signed1,
                                       clock=self.present)
        self.assertIs(decoded1, None)
        decoded2 = decode_signed_value(SignedValueTest.SECRET, "key1", signed2,
                                       clock=self.present)
        self.assertIs(decoded2, None)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_expired(self):
        signed = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                     clock=self.past)
        decoded_past = decode_signed_value(SignedValueTest.SECRET, "key1",
                                           signed, clock=self.past)
        self.assertEqual(decoded_past, b"value")
        decoded_present = decode_signed_value(SignedValueTest.SECRET, "key1",
                                              signed, clock=self.present)
        self.assertIs(decoded_present, None)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_non_ascii(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET, "key", value,
                                     clock=self.present)
        decoded = decode_signed_value(SignedValueTest.SECRET, "key", signed,
                                      clock=self.present)
        self.assertEqual(value, decoded)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_key_versioning_read_write_non_default_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=1)
        decoded = decode_signed_value(SignedValueTest.SECRET_DICT,
                                      "key", signed, clock=self.present)
        self.assertEqual(value, decoded)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_key_versioning_invalid_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=0)
        newkeys = SignedValueTest.SECRET_DICT.copy()
        newkeys.pop(0)
        decoded = decode_signed_value(newkeys,
                                      "key", signed, clock=self.present)
        self.assertEqual(None, decoded)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_key_version_retrieval(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=1)
        key_version = get_signature_key_version(signed)
        self.assertEqual(1, key_version)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_types(self):
        cookie_value = to_unicode(create_signed_value(self.COOKIE_SECRET,
                                                      "asdf", "qwer"))
        response = self.fetch("/typecheck/asdf?foo=bar",
                              headers={"Cookie": "asdf=" + cookie_value})
        data = json_decode(response.body)
        self.assertEqual(data, {})

        response = self.fetch("/typecheck/asdf?foo=bar", method="POST",
                              headers={"Cookie": "asdf=" + cookie_value},
                              body="foo=bar")
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_known_values(self):
        signed_v1 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=1, clock=self.present)
        self.assertEqual(
            signed_v1,
            b"dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4f")

        signed_v2 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=2, clock=self.present)
        self.assertEqual(
            signed_v2,
            b"2|1:0|10:1300000000|3:key|8:dmFsdWU=|"
            b"3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152")

        signed_default = create_signed_value(SignedValueTest.SECRET,
                                             "key", "value", clock=self.present)
        self.assertEqual(signed_default, signed_v2)

        decoded_v1 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v1, min_version=1,
                                         clock=self.present)
        self.assertEqual(decoded_v1, b"value")

        decoded_v2 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v2, min_version=2,
                                         clock=self.present)
        self.assertEqual(decoded_v2, b"value")
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_expired(self):
        signed = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                     clock=self.past)
        decoded_past = decode_signed_value(SignedValueTest.SECRET, "key1",
                                           signed, clock=self.past)
        self.assertEqual(decoded_past, b"value")
        decoded_present = decode_signed_value(SignedValueTest.SECRET, "key1",
                                              signed, clock=self.present)
        self.assertIs(decoded_present, None)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_non_ascii(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET, "key", value,
                                     clock=self.present)
        decoded = decode_signed_value(SignedValueTest.SECRET, "key", signed,
                                      clock=self.present)
        self.assertEqual(value, decoded)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_key_versioning_read_write_default_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=0)
        decoded = decode_signed_value(SignedValueTest.SECRET_DICT,
                                      "key", signed, clock=self.present)
        self.assertEqual(value, decoded)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_key_versioning_read_write_non_default_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=1)
        decoded = decode_signed_value(SignedValueTest.SECRET_DICT,
                                      "key", signed, clock=self.present)
        self.assertEqual(value, decoded)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_key_versioning_invalid_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=0)
        newkeys = SignedValueTest.SECRET_DICT.copy()
        newkeys.pop(0)
        decoded = decode_signed_value(newkeys,
                                      "key", signed, clock=self.present)
        self.assertEqual(None, decoded)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_types(self):
        cookie_value = to_unicode(create_signed_value(self.COOKIE_SECRET,
                                                      "asdf", "qwer"))
        response = self.fetch("/typecheck/asdf?foo=bar",
                              headers={"Cookie": "asdf=" + cookie_value})
        data = json_decode(response.body)
        self.assertEqual(data, {})

        response = self.fetch("/typecheck/asdf?foo=bar", method="POST",
                              headers={"Cookie": "asdf=" + cookie_value},
                              body="foo=bar")
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_known_values(self):
        signed_v1 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=1, clock=self.present)
        self.assertEqual(
            signed_v1,
            b"dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4f")

        signed_v2 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=2, clock=self.present)
        self.assertEqual(
            signed_v2,
            b"2|1:0|10:1300000000|3:key|8:dmFsdWU=|"
            b"3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152")

        signed_default = create_signed_value(SignedValueTest.SECRET,
                                             "key", "value", clock=self.present)
        self.assertEqual(signed_default, signed_v2)

        decoded_v1 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v1, min_version=1,
                                         clock=self.present)
        self.assertEqual(decoded_v1, b"value")

        decoded_v2 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v2, min_version=2,
                                         clock=self.present)
        self.assertEqual(decoded_v2, b"value")
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_name_swap(self):
        signed1 = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                      clock=self.present)
        signed2 = create_signed_value(SignedValueTest.SECRET, "key2", "value",
                                      clock=self.present)
        # Try decoding each string with the other's "name"
        decoded1 = decode_signed_value(SignedValueTest.SECRET, "key2", signed1,
                                       clock=self.present)
        self.assertIs(decoded1, None)
        decoded2 = decode_signed_value(SignedValueTest.SECRET, "key1", signed2,
                                       clock=self.present)
        self.assertIs(decoded2, None)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_expired(self):
        signed = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                     clock=self.past)
        decoded_past = decode_signed_value(SignedValueTest.SECRET, "key1",
                                           signed, clock=self.past)
        self.assertEqual(decoded_past, b"value")
        decoded_present = decode_signed_value(SignedValueTest.SECRET, "key1",
                                              signed, clock=self.present)
        self.assertIs(decoded_present, None)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_non_ascii(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET, "key", value,
                                     clock=self.present)
        decoded = decode_signed_value(SignedValueTest.SECRET, "key", signed,
                                      clock=self.present)
        self.assertEqual(value, decoded)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_key_versioning_read_write_non_default_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=1)
        decoded = decode_signed_value(SignedValueTest.SECRET_DICT,
                                      "key", signed, clock=self.present)
        self.assertEqual(value, decoded)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_key_versioning_invalid_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=0)
        newkeys = SignedValueTest.SECRET_DICT.copy()
        newkeys.pop(0)
        decoded = decode_signed_value(newkeys,
                                      "key", signed, clock=self.present)
        self.assertEqual(None, decoded)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def test_key_version_retrieval(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=1)
        key_version = get_signature_key_version(signed)
        self.assertEqual(1, key_version)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def test_types(self):
        cookie_value = to_unicode(create_signed_value(self.COOKIE_SECRET,
                                                      "asdf", "qwer"))
        response = self.fetch("/typecheck/asdf?foo=bar",
                              headers={"Cookie": "asdf=" + cookie_value})
        data = json_decode(response.body)
        self.assertEqual(data, {})

        response = self.fetch("/typecheck/asdf?foo=bar", method="POST",
                              headers={"Cookie": "asdf=" + cookie_value},
                              body="foo=bar")
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def test_known_values(self):
        signed_v1 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=1, clock=self.present)
        self.assertEqual(
            signed_v1,
            b"dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4f")

        signed_v2 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=2, clock=self.present)
        self.assertEqual(
            signed_v2,
            b"2|1:0|10:1300000000|3:key|8:dmFsdWU=|"
            b"3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152")

        signed_default = create_signed_value(SignedValueTest.SECRET,
                                             "key", "value", clock=self.present)
        self.assertEqual(signed_default, signed_v2)

        decoded_v1 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v1, min_version=1,
                                         clock=self.present)
        self.assertEqual(decoded_v1, b"value")

        decoded_v2 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v2, min_version=2,
                                         clock=self.present)
        self.assertEqual(decoded_v2, b"value")
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def test_name_swap(self):
        signed1 = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                      clock=self.present)
        signed2 = create_signed_value(SignedValueTest.SECRET, "key2", "value",
                                      clock=self.present)
        # Try decoding each string with the other's "name"
        decoded1 = decode_signed_value(SignedValueTest.SECRET, "key2", signed1,
                                       clock=self.present)
        self.assertIs(decoded1, None)
        decoded2 = decode_signed_value(SignedValueTest.SECRET, "key1", signed2,
                                       clock=self.present)
        self.assertIs(decoded2, None)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def test_expired(self):
        signed = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                     clock=self.past)
        decoded_past = decode_signed_value(SignedValueTest.SECRET, "key1",
                                           signed, clock=self.past)
        self.assertEqual(decoded_past, b"value")
        decoded_present = decode_signed_value(SignedValueTest.SECRET, "key1",
                                              signed, clock=self.present)
        self.assertIs(decoded_present, None)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def test_non_ascii(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET, "key", value,
                                     clock=self.present)
        decoded = decode_signed_value(SignedValueTest.SECRET, "key", signed,
                                      clock=self.present)
        self.assertEqual(value, decoded)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def test_key_versioning_read_write_non_default_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=1)
        decoded = decode_signed_value(SignedValueTest.SECRET_DICT,
                                      "key", signed, clock=self.present)
        self.assertEqual(value, decoded)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def test_key_versioning_invalid_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=0)
        newkeys = SignedValueTest.SECRET_DICT.copy()
        newkeys.pop(0)
        decoded = decode_signed_value(newkeys,
                                      "key", signed, clock=self.present)
        self.assertEqual(None, decoded)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def test_key_version_retrieval(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=1)
        key_version = get_signature_key_version(signed)
        self.assertEqual(1, key_version)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_types(self):
        cookie_value = to_unicode(create_signed_value(self.COOKIE_SECRET,
                                                      "asdf", "qwer"))
        response = self.fetch("/typecheck/asdf?foo=bar",
                              headers={"Cookie": "asdf=" + cookie_value})
        data = json_decode(response.body)
        self.assertEqual(data, {})

        response = self.fetch("/typecheck/asdf?foo=bar", method="POST",
                              headers={"Cookie": "asdf=" + cookie_value},
                              body="foo=bar")
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_known_values(self):
        signed_v1 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=1, clock=self.present)
        self.assertEqual(
            signed_v1,
            b"dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4f")

        signed_v2 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=2, clock=self.present)
        self.assertEqual(
            signed_v2,
            b"2|1:0|10:1300000000|3:key|8:dmFsdWU=|"
            b"3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152")

        signed_default = create_signed_value(SignedValueTest.SECRET,
                                             "key", "value", clock=self.present)
        self.assertEqual(signed_default, signed_v2)

        decoded_v1 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v1, min_version=1,
                                         clock=self.present)
        self.assertEqual(decoded_v1, b"value")

        decoded_v2 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v2, min_version=2,
                                         clock=self.present)
        self.assertEqual(decoded_v2, b"value")
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_name_swap(self):
        signed1 = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                      clock=self.present)
        signed2 = create_signed_value(SignedValueTest.SECRET, "key2", "value",
                                      clock=self.present)
        # Try decoding each string with the other's "name"
        decoded1 = decode_signed_value(SignedValueTest.SECRET, "key2", signed1,
                                       clock=self.present)
        self.assertIs(decoded1, None)
        decoded2 = decode_signed_value(SignedValueTest.SECRET, "key1", signed2,
                                       clock=self.present)
        self.assertIs(decoded2, None)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_expired(self):
        signed = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                     clock=self.past)
        decoded_past = decode_signed_value(SignedValueTest.SECRET, "key1",
                                           signed, clock=self.past)
        self.assertEqual(decoded_past, b"value")
        decoded_present = decode_signed_value(SignedValueTest.SECRET, "key1",
                                              signed, clock=self.present)
        self.assertIs(decoded_present, None)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_non_ascii(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET, "key", value,
                                     clock=self.present)
        decoded = decode_signed_value(SignedValueTest.SECRET, "key", signed,
                                      clock=self.present)
        self.assertEqual(value, decoded)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_known_values(self):
        signed_v1 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=1, clock=self.present)
        self.assertEqual(
            signed_v1,
            b"dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4f")

        signed_v2 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=2, clock=self.present)
        self.assertEqual(
            signed_v2,
            b"2|1:0|10:1300000000|3:key|8:dmFsdWU=|"
            b"3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152")

        signed_default = create_signed_value(SignedValueTest.SECRET,
                                             "key", "value", clock=self.present)
        self.assertEqual(signed_default, signed_v2)

        decoded_v1 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v1, min_version=1,
                                         clock=self.present)
        self.assertEqual(decoded_v1, b"value")

        decoded_v2 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v2, min_version=2,
                                         clock=self.present)
        self.assertEqual(decoded_v2, b"value")
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_name_swap(self):
        signed1 = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                      clock=self.present)
        signed2 = create_signed_value(SignedValueTest.SECRET, "key2", "value",
                                      clock=self.present)
        # Try decoding each string with the other's "name"
        decoded1 = decode_signed_value(SignedValueTest.SECRET, "key2", signed1,
                                       clock=self.present)
        self.assertIs(decoded1, None)
        decoded2 = decode_signed_value(SignedValueTest.SECRET, "key1", signed2,
                                       clock=self.present)
        self.assertIs(decoded2, None)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_expired(self):
        signed = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                     clock=self.past)
        decoded_past = decode_signed_value(SignedValueTest.SECRET, "key1",
                                           signed, clock=self.past)
        self.assertEqual(decoded_past, b"value")
        decoded_present = decode_signed_value(SignedValueTest.SECRET, "key1",
                                              signed, clock=self.present)
        self.assertIs(decoded_present, None)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_non_ascii(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET, "key", value,
                                     clock=self.present)
        decoded = decode_signed_value(SignedValueTest.SECRET, "key", signed,
                                      clock=self.present)
        self.assertEqual(value, decoded)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_key_versioning_read_write_default_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=0)
        decoded = decode_signed_value(SignedValueTest.SECRET_DICT,
                                      "key", signed, clock=self.present)
        self.assertEqual(value, decoded)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_key_versioning_invalid_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=0)
        newkeys = SignedValueTest.SECRET_DICT.copy()
        newkeys.pop(0)
        decoded = decode_signed_value(newkeys,
                                      "key", signed, clock=self.present)
        self.assertEqual(None, decoded)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_key_version_retrieval(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=1)
        key_version = get_signature_key_version(signed)
        self.assertEqual(1, key_version)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_types(self):
        cookie_value = to_unicode(create_signed_value(self.COOKIE_SECRET,
                                                      "asdf", "qwer"))
        response = self.fetch("/typecheck/asdf?foo=bar",
                              headers={"Cookie": "asdf=" + cookie_value})
        data = json_decode(response.body)
        self.assertEqual(data, {})

        response = self.fetch("/typecheck/asdf?foo=bar", method="POST",
                              headers={"Cookie": "asdf=" + cookie_value},
                              body="foo=bar")
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_known_values(self):
        signed_v1 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=1, clock=self.present)
        self.assertEqual(
            signed_v1,
            b"dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4f")

        signed_v2 = create_signed_value(SignedValueTest.SECRET, "key", "value",
                                        version=2, clock=self.present)
        self.assertEqual(
            signed_v2,
            b"2|1:0|10:1300000000|3:key|8:dmFsdWU=|"
            b"3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152")

        signed_default = create_signed_value(SignedValueTest.SECRET,
                                             "key", "value", clock=self.present)
        self.assertEqual(signed_default, signed_v2)

        decoded_v1 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v1, min_version=1,
                                         clock=self.present)
        self.assertEqual(decoded_v1, b"value")

        decoded_v2 = decode_signed_value(SignedValueTest.SECRET, "key",
                                         signed_v2, min_version=2,
                                         clock=self.present)
        self.assertEqual(decoded_v2, b"value")
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_name_swap(self):
        signed1 = create_signed_value(SignedValueTest.SECRET, "key1", "value",
                                      clock=self.present)
        signed2 = create_signed_value(SignedValueTest.SECRET, "key2", "value",
                                      clock=self.present)
        # Try decoding each string with the other's "name"
        decoded1 = decode_signed_value(SignedValueTest.SECRET, "key2", signed1,
                                       clock=self.present)
        self.assertIs(decoded1, None)
        decoded2 = decode_signed_value(SignedValueTest.SECRET, "key1", signed2,
                                       clock=self.present)
        self.assertIs(decoded2, None)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_non_ascii(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET, "key", value,
                                     clock=self.present)
        decoded = decode_signed_value(SignedValueTest.SECRET, "key", signed,
                                      clock=self.present)
        self.assertEqual(value, decoded)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_key_versioning_read_write_default_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=0)
        decoded = decode_signed_value(SignedValueTest.SECRET_DICT,
                                      "key", signed, clock=self.present)
        self.assertEqual(value, decoded)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_key_versioning_read_write_non_default_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=1)
        decoded = decode_signed_value(SignedValueTest.SECRET_DICT,
                                      "key", signed, clock=self.present)
        self.assertEqual(value, decoded)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def test_key_versioning_invalid_key(self):
        value = b"\xe9"
        signed = create_signed_value(SignedValueTest.SECRET_DICT,
                                     "key", value, clock=self.present,
                                     key_version=0)
        newkeys = SignedValueTest.SECRET_DICT.copy()
        newkeys.pop(0)
        decoded = decode_signed_value(newkeys,
                                      "key", signed, clock=self.present)
        self.assertEqual(None, decoded)