Ejemplo n.º 1
0
    def test_delete_canary(self):
        """Test that deleting a canary removes it from the database and
        the filesystem.
        """
        c = self._create_canary()
        self._login()
        r = self.app.post(
            '/canary/{}/delete'.format(c.sigid_base64),
            follow_redirects=True)

        canary_file = '{}/{}'.format(self.canaries_dir, c.sigid_base64)

        self.assertEqual(db_session.query(Canary).count(), 0)
        self.assertFalse(os.path.isfile(canary_file))
        self.assertIn(messages['deleted'], r.data)
Ejemplo n.º 2
0
    def test_decrypt_fail_publish_canary(self):
        """Test that submitting an invalid secret displays an error
        message and does not post a new Canary.
        """
        with self.app as a:
            self._submit_message(self.valid_msg)
            sigid = session['canary']['sigid_base64']
            canary_file = os.path.join(self.canaries_dir, sigid)

            r = a.post('/canary/{}'.format(sigid),
                       data={'decrypted': 'incorrect'},
                       follow_redirects=True)

            self.assertIn(err_messages['decrypt_fail'], r.data)
            self.assertEqual(db_session.query(Canary).count(), 0)
            self.assertFalse(os.path.isfile(canary_file))
Ejemplo n.º 3
0
    def test_decrypt_success_publish_canary(self):
        """Test that decrypting the secret creates a new Canary."""
        with self.app as a:
            r1 = self._submit_message(self.valid_msg)
            sigid = session['canary']['sigid_base64']
            url = '/canary/' + sigid
            canary_file = os.path.join(self.canaries_dir, sigid)

            r = a.post(url,
                       data=dict(decrypted=self._decrypt_challenge(r1.data)),
                       follow_redirects=True)

            self.assertIn(messages['published'], r.data)
            self.assertEqual(db_session.query(Canary).count(), 1)

            # Check that the canary is in the filesystem
            self.assertTrue(os.path.isfile(canary_file))
            self.assertIn(self.valid_msg, open(canary_file).read())