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:22.83 GB of 70.42 GB (32.42%)
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/ share/ pyshared/ lazr/ restfulclient/ tests/ - drwxr-xr-x

Directory:
Viewing file:     test_oauth.py (5.85 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
# Copyright 2009 Canonical Ltd.

# This file is part of lazr.restfulclient.
#
# lazr.restfulclient is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, version 3 of the
# License.
#
# lazr.restfulclient is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with lazr.restfulclient. If not, see <http://www.gnu.org/licenses/>.

"""Tests for the OAuth-aware classes."""

__metaclass__ = type


import os
import os.path
import shutil
import stat
import tempfile
import unittest

from lazr.restfulclient.authorize import oauth
from lazr.restfulclient.authorize.oauth import (
    AccessToken,
    Consumer,
    OAuthAuthorizer,
    )


class TestConsumer(unittest.TestCase):

    def test_data_fields(self):
        consumer = Consumer("key", "secret", "application")
        self.assertEquals(consumer.key, "key")
        self.assertEquals(consumer.secret, "secret")
        self.assertEquals(consumer.application_name, "application")

    def test_default_application_name(self):
        # Application name defaults to None
        consumer = Consumer("key", "secret")
        self.assertEquals(consumer.application_name, None)


class TestSystemWideConsumer(unittest.TestCase):

    def setUp(self):
        """Save the original 'platform' and 'socket' modules.

        The tests will be replacing them with dummies.
        """
        self.original_platform = oauth.platform
        self.original_socket = oauth.socket

    def tearDown(self):
        """Replace the original 'platform' and 'socket' modules."""
        oauth.platform = self.original_platform
        oauth.socket = self.original_socket

    def _set_hostname(self, hostname):
        """Changes the socket module to simulate the given hostname."""
        class DummySocket:
            def gethostname(self):
                return hostname
        oauth.socket = DummySocket()

    def _set_platform(self, linux_distribution, system):
        """Changes the platform module to simulate different behavior.

        :param linux_distribution: A tuple to be returned by
            linux_distribution(), or a callable that implements
            linux_distribution().
        :param system: A string to be returned by system()
        """

        if isinstance(linux_distribution, tuple):
            def get_linux_distribution(self):
                return linux_distribution
        else:
            # The caller provided their own implementation of
            # linux_distribution().
            get_linux_distribution = linux_distribution

        class DummyPlatform:
            linux_distribution = get_linux_distribution
            def system(self):
                return system
        oauth.platform = DummyPlatform()

    def _broken(self):
        """Raises an exception."""
        raise Exception("Oh noes!")

    def test_useful_linux_distribution(self):
        # If platform.linux_distribution returns a tuple of useful
        # strings, as it does on Ubuntu, we'll use the first string
        # for the system type.
        self._set_platform(('Fooix', 'String2', 'String3'), 'FooOS')
        self._set_hostname("foo")
        consumer = oauth.SystemWideConsumer("app name")
        self.assertEquals(
            consumer.key, 'System-wide: Fooix (foo)')

    def test_empty_linux_distribution(self):
        # If platform.linux_distribution returns a tuple of empty
        # strings, as it does on Windows and Mac OS X, we fall back to
        # the result of platform.system().
        self._set_platform(('', '', ''), 'BarOS')
        self._set_hostname("bar")
        consumer = oauth.SystemWideConsumer("app name")
        self.assertEquals(
            consumer.key, 'System-wide: BarOS (bar)')

    def test_broken_linux_distribution(self):
        # If platform.linux_distribution raises an exception (which
        # can happen with older versions of Python), we fall back to
        # the result of platform.system().
        self._set_platform(self._broken, 'BazOS')
        self._set_hostname("baz")
        consumer = oauth.SystemWideConsumer("app name")
        self.assertEquals(
            consumer.key, 'System-wide: BazOS (baz)')


class TestOAuthAuthorizer(unittest.TestCase):
    """Test for the OAuth Authorizer."""

    def setUp(self):
        self.temp_dir = tempfile.mkdtemp()

    def tearDown(self):
        shutil.rmtree(self.temp_dir)

    def test_save_to_and_load_from__path(self):
        # Credentials can be saved to and loaded from a file using
        # save_to_path() and load_from_path().
        credentials_path = os.path.join(self.temp_dir, 'credentials')
        credentials = OAuthAuthorizer(
            'consumer.key', consumer_secret='consumer.secret',
            access_token=AccessToken('access.key', 'access.secret'))
        credentials.save_to_path(credentials_path)
        self.assertTrue(os.path.exists(credentials_path))

        # Make sure the file is readable and writable by the user, but
        # not by anyone else.
        self.assertEquals(stat.S_IMODE(os.stat(credentials_path).st_mode),
                          stat.S_IREAD | stat.S_IWRITE)

        loaded_credentials = OAuthAuthorizer.load_from_path(credentials_path)
        self.assertEqual(loaded_credentials.consumer.key, 'consumer.key')
        self.assertEqual(
            loaded_credentials.consumer.secret, 'consumer.secret')
        self.assertEqual(
            loaded_credentials.access_token.key, 'access.key')
        self.assertEqual(
            loaded_credentials.access_token.secret, 'access.secret')

def test_suite():
    return unittest.TestLoader().loadTestsFromName(__name__)
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: 0.2458 seconds