コード例 #1
0
 def test_password_is_not_stored_in_plaintext(self):
     password = "******"
     token = snappass.set_password(password, 30)
     redis_key = token.split(snappass.TOKEN_SEPARATOR)[0]
     stored_password_text = snappass.redis_client.get(redis_key).decode(
         'utf-8')
     self.assertNotIn(password, stored_password_text)
コード例 #2
0
ファイル: tests.py プロジェクト: pinterest/snappass
 def test_password_after_expiration(self):
     password = '******'
     key = snappass.set_password(password, 1)
     time.sleep(1.5)
     # Expire functionality must be explicitly invoked using do_expire(time).
     # mockredis does not support automatic expiration at this time
     snappass.redis_client.do_expire()
     self.assertIsNone(snappass.get_password(key))
コード例 #3
0
 def test_password_after_expiration(self):
     password = '******'
     key = snappass.set_password(password, 1)
     time.sleep(1.5)
     # Expire functionality must be explicitly invoked using do_expire(time).
     # mockredis does not support automatic expiration at this time
     snappass.redis_client.do_expire()
     self.assertIsNone(snappass.get_password(key))
コード例 #4
0
ファイル: tests.py プロジェクト: pinterest/snappass
 def test_encryption_key_is_returned(self):
     password = "******"
     token = snappass.set_password(password, 30)
     token_fragments = token.split(snappass.TOKEN_SEPARATOR)
     redis_key, encryption_key = token_fragments
     stored_password = snappass.redis_client.get(redis_key)
     fernet = Fernet(encryption_key.encode('utf-8'))
     decrypted_password = fernet.decrypt(stored_password).decode('utf-8')
     self.assertEqual(password, decrypted_password)
コード例 #5
0
 def test_encryption_key_is_returned(self):
     password = "******"
     token = snappass.set_password(password, 30)
     token_fragments = token.split(snappass.TOKEN_SEPARATOR)
     redis_key, encryption_key = token_fragments
     stored_password = snappass.redis_client.get(redis_key)
     fernet = Fernet(encryption_key.encode('utf-8'))
     decrypted_password = fernet.decrypt(stored_password).decode('utf-8')
     self.assertEqual(password, decrypted_password)
コード例 #6
0
ファイル: tests.py プロジェクト: pinterest/snappass
 def test_returned_token_format(self):
     password = "******"
     token = snappass.set_password(password, 30)
     token_fragments = token.split(snappass.TOKEN_SEPARATOR)
     self.assertEqual(2, len(token_fragments))
     redis_key, encryption_key = token_fragments
     self.assertEqual(32 + len(snappass.REDIS_PREFIX), len(redis_key))
     try:
         Fernet(encryption_key.encode('utf-8'))
     except ValueError:
         self.fail('the encryption key is not valid')
コード例 #7
0
 def test_returned_token_format(self):
     password = "******"
     token = snappass.set_password(password, 30)
     token_fragments = token.split(snappass.TOKEN_SEPARATOR)
     self.assertEqual(2, len(token_fragments))
     redis_key, encryption_key = token_fragments
     self.assertEqual(32 + len(snappass.REDIS_PREFIX), len(redis_key))
     try:
         Fernet(encryption_key.encode('utf-8'))
     except ValueError:
         self.fail('the encryption key is not valid')
コード例 #8
0
    def test_bots_denial(self):
        """
        Main known bots User-Agent should be denied access
        """
        password = "******"
        key = snappass.set_password(password, 30)
        a_few_sneaky_bots = [
            "Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)",
            "facebookexternalhit/1.1", "Facebot/1.0", "Twitterbot/1.0",
            "_WhatsApp/2.12.81 (Windows NT 6.1; U; es-ES) Presto/2.9.181 Version/12.00",
            "WhatsApp/2.16.6/i", "SkypeUriPreview Preview/0.5"
        ]

        for ua in a_few_sneaky_bots:
            rv = self.app.get('/{0}'.format(key), headers={'User-Agent': ua})
            self.assertEquals(rv.status_code, 404)
コード例 #9
0
ファイル: tests.py プロジェクト: clmoreno/snappass
    def test_bots_denial(self):
        """
        Main known bots User-Agent should be denied access
        """
        password = "******"
        key = snappass.set_password(password, 30)
        a_few_sneaky_bots = [
            "Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)",
            "facebookexternalhit/1.1",
            "Facebot/1.0",
            "Twitterbot/1.0",
            "_WhatsApp/2.12.81 (Windows NT 6.1; U; es-ES) Presto/2.9.181 Version/12.00",
            "WhatsApp/2.16.6/i",
            "SkypeUriPreview Preview/0.5"
        ]

        for ua in a_few_sneaky_bots:
            rv = self.app.get('/{0}'.format(key), headers={ 'User-Agent': ua })
            self.assertEquals(rv.status_code, 404)
コード例 #10
0
ファイル: tests.py プロジェクト: WilliamRen/snappass
 def test_show_password(self):
     password = "******"
     key = snappass.set_password(password, 30)
     rv = self.app.get('/{}'.format(key))
     self.assertIn(password, rv.data)
コード例 #11
0
 def test_password_after_expiration(self):
     password = '******'
     key = snappass.set_password(password, 1)
     time.sleep(1.5)
     self.assertEqual(None, snappass.get_password(key))
コード例 #12
0
 def test_password_is_decoded(self):
     password = "******"
     key = snappass.set_password(password, 30)
     self.assertFalse(isinstance(snappass.get_password(key), bytes))
コード例 #13
0
 def test_set_password(self):
     """Ensure we return a 32-bit key."""
     key = snappass.set_password("foo", 30)
     self.assertEqual(32, len(key))
コード例 #14
0
ファイル: tests.py プロジェクト: jameswthorne/snappass
 def test_password_before_expiration(self):
     password = '******'
     key = snappass.set_password(password, 1)
     self.assertEqual(password, snappass.get_password(key))
コード例 #15
0
ファイル: tests.py プロジェクト: jameswthorne/snappass
 def test_password_is_decoded(self):
     password = "******"
     key = snappass.set_password(password, 30)
     self.assertFalse(isinstance(snappass.get_password(key), bytes))
コード例 #16
0
 def test_show_password(self):
     password = "******"
     key = snappass.set_password(password, 30)
     rv = self.app.get('/{}'.format(key))
     self.assertIn(password, rv.data)
コード例 #17
0
ファイル: tests.py プロジェクト: jameswthorne/snappass
 def test_password_after_expiration(self):
     password = '******'
     key = snappass.set_password(password, 1)
     time.sleep(1.5)
     self.assertEqual(None, snappass.get_password(key))
コード例 #18
0
ファイル: tests.py プロジェクト: jameswthorne/snappass
 def test_show_password(self):
     password = "******"
     key = snappass.set_password(password, 30)
     rv = self.app.get('/{0}'.format(key))
     self.assertTrue(password in rv.get_data(as_text=True))
コード例 #19
0
 def test_get_password(self):
     password = "******"
     key = snappass.set_password(password, 30)
     self.assertEqual(password, snappass.get_password(key))
     # Assert that we can't look this up a second time.
     self.assertEqual(None, snappass.get_password(key))
コード例 #20
0
ファイル: tests.py プロジェクト: WilliamRen/snappass
 def test_set_password(self):
     """Ensure we return a 32-bit key."""
     key = snappass.set_password("foo", 30)
     self.assertEqual(32, len(key))
コード例 #21
0
 def test_password_before_expiration(self):
     password = '******'
     key = snappass.set_password(password, 1)
     self.assertEqual(password, snappass.get_password(key))
コード例 #22
0
ファイル: tests.py プロジェクト: WilliamRen/snappass
 def test_get_password(self):
     password = "******"
     key = snappass.set_password(password, 30)
     self.assertEqual(password, snappass.get_password(key))
     # Assert that we can't look this up a second time.
     self.assertEqual(None, snappass.get_password(key))
コード例 #23
0
 def test_show_password(self):
     password = "******"
     key = snappass.set_password(password, 30)
     rv = self.app.get('/{0}'.format(key))
     self.assertTrue(password in rv.get_data(as_text=True))
コード例 #24
0
ファイル: tests.py プロジェクト: pinterest/snappass
 def test_password_is_not_stored_in_plaintext(self):
     password = "******"
     token = snappass.set_password(password, 30)
     redis_key = token.split(snappass.TOKEN_SEPARATOR)[0]
     stored_password_text = snappass.redis_client.get(redis_key).decode('utf-8')
     self.assertNotIn(password, stored_password_text)