Exemplo n.º 1
0
    def test_multifile_paste(self):
        badPastes = [
            pastebin.BadPaste(u'testbadpb', u'first'),
            pastebin.BadPaste(u'testbadpb', u'second'),
        ]
        expectedRepastedUrl = u'https://paste.example.com/outputid'
        self.fakeContentFromPaste.reset([
            b"first's content\n",
            b"second's content\n",
        ])
        self.fakeCreatePaste.reset([expectedRepastedUrl])
        self.repaster._cache._now = lambda: 1

        repastedUrl = yield self.repaster.repaste(badPastes)

        self.assertEqual(repastedUrl, expectedRepastedUrl)
        expectedPastedContent = (b'### testbadpb::first.py\n'
                                 b"first's content\n"
                                 b'\n'
                                 b'### testbadpb::second.py\n'
                                 b"second's content\n")
        self.assertEqual(
            self.fakeContentFromPaste.calls,
            [sp.Call(bp) for bp in badPastes],
        )
        self.assertEqual(
            self.fakeCreatePaste.calls,
            [sp.Call(expectedPastedContent, u'multi')],
        )
Exemplo n.º 2
0
    def test_edit_ban(self):
        ban = (
            b'#project',
            b'$a:baduser',
            b'b',
            dt('2018-03-14T15:09:26'),
            b'someop!foo',
            dt('2018-03-21T15:09:26'),
            b'bad behavior',
            None,
            b'',
        )
        dbpool = sp.FakeObj()
        dbpool.get_ban_with_auth = sp.DeferredSequentialReturner([ban])
        yield self.startWebUI(dbpool)

        res, content = yield self.get(b'/bans/edit/5/deadbeef')
        self.assertEqual(
            dbpool.get_ban_with_auth.calls,
            [sp.Call(b'5', b'deadbeef')],
        )
        self.assertEqual(res.code, 200)
        self.assertIn(b'<form', content)
        self.assertIn(b'#project', content)
        self.assertIn(b'$a:baduser', content)
        self.assertIn(b'bad behavior', content)
Exemplo n.º 3
0
    def test_post_edit_ban(self):
        ban = (
            b'#project',
            b'$a:baduser',
            b'b',
            dt('2018-03-14T15:09:26'),
            b'someop!foo',
            dt('2018-03-21T15:09:26'),
            b'bad behavior',
            None,
            b'',
        )
        dbpool = sp.FakeObj()
        dbpool.get_ban_with_auth = sp.DeferredSequentialReturner([ban])
        dbpool.update_ban_by_rowid = sp.DeferredSequentialReturner([None])
        yield self.startWebUI(dbpool)

        res, content = yield self.post(
            b'/bans/edit/5/deadbeef',
            {
                b'expire_at': b'never',
                b'reason': b'they lost their chance'
            },
        )
        self.assertEqual(
            dbpool.get_ban_with_auth.calls,
            [sp.Call(b'5', b'deadbeef')],
        )
        self.assertEqual(
            dbpool.update_ban_by_rowid.calls,
            [sp.Call(b'5', None, b'they lost their chance')],
        )
        self.assertEqual(res.code, 200)
        self.assertIn(b'<form', content)
        self.assertIn(b'#project', content)
        self.assertIn(b'never', content)
        self.assertIn(b'$a:baduser', content)
        self.assertIn(b'they lost their chance', content)
Exemplo n.º 4
0
    def test_basic_cacheing(self):
        badPaste = pastebin.BadPaste(u'testbadpb', u'allgood')
        expectedRepastedUrl = u'https://paste.example.com/outputid'
        self.fakeContentFromPaste.reset([b'testing testing'])
        self.fakeCreatePaste.reset([expectedRepastedUrl])
        self.repaster._cache._now = lambda: 1

        repastedUrl = yield self.repaster.repaste([badPaste])

        self.assertEqual(
            self.fakeContentFromPaste.calls,
            [sp.Call(badPaste)],
        )
        self.assertEqual(
            self.fakeCreatePaste.calls,
            [sp.Call(b'testing testing', u'python')],
        )
        self.assertEqual(repastedUrl, expectedRepastedUrl)

        # Now make sure these aren't called, only the cache is involved.
        self.fakeContentFromPaste.reset([])
        self.fakeCreatePaste.reset([])

        self.repaster._cache._now = lambda: 2
        repastedUrl = yield self.repaster.repaste([badPaste])
        self.assertEqual(self.fakeContentFromPaste.calls, [])
        self.assertEqual(self.fakeCreatePaste.calls, [])
        # Too soon, so should be None.
        self.assertIsNone(repastedUrl)

        self.repaster._cache._now = lambda: 20
        repastedUrl = yield self.repaster.repaste([badPaste])
        self.assertEqual(self.fakeContentFromPaste.calls, [])
        self.assertEqual(self.fakeCreatePaste.calls, [])
        # After enough of a delay, the url comes through.
        self.assertEqual(repastedUrl, expectedRepastedUrl)
Exemplo n.º 5
0
 def test_identify_delegates(self):
     idFinder = sp.SequentialReturner([u'1234'])
     bp = self.makeOne(idFinder)
     result = bp.identifyPaste(
         u'paste.example.com',
         u'/id/path',
         u'',
         u'',
         u'',
     )
     self.assertEqual(
         result,
         pastebin.BadPaste(u'paste.example.com', u'1234'),
     )
     expectedCall = sp.Call(u'/id/path')
     self.assertEqual(idFinder.calls, [expectedCall])