Beispiel #1
0
class UbuntuSSOAPIFake(UbuntuSSOAPI):
    def __init__(self):
        GObject.GObject.__init__(self)
        self._fake_settings = FakeReviewSettings()

    @network_delay
    def whoami(self):
        if self._fake_settings.get_setting('whoami_response') == "whoami":
            self.emit("whoami", self._create_whoami_response())
        elif self._fake_settings.get_setting('whoami_response') == "error":
            self.emit("error", self._make_error())

    def _create_whoami_response(self):
        username = (self._fake_settings.get_setting('whoami_username')
                    or "anyuser")
        response = {
            u'username': username.decode('utf-8'),
            u'preferred_email': u'*****@*****.**',
            u'displayname': u'Fake User',
            u'unverified_emails': [],
            u'verified_emails': [],
            u'openid_identifier': u'fnerkWt'
        }
        return response

    def _make_error():
        return 'HTTP Error 401: Unauthorized'
Beispiel #2
0
class UbuntuSSOAPIFake(UbuntuSSO):

    def __init__(self):
        UbuntuSSO.__init__(self)
        self._fake_settings = FakeReviewSettings()

    @network_delay
    def whoami(self):
        if self._fake_settings.get_setting('whoami_response') == "whoami":
            self.emit("whoami", self._create_whoami_response())
        elif self._fake_settings.get_setting('whoami_response') == "error":
            self.emit("error", self._make_error())

    def _create_whoami_response(self):
        username = (self._fake_settings.get_setting('whoami_username') or
            "anyuser")
        response = {
                    u'username': username.decode('utf-8'),
                    u'preferred_email': u'*****@*****.**',
                    u'displayname': u'Fake User',
                    u'unverified_emails': [],
                    u'verified_emails': [],
                    u'openid_identifier': u'fnerkWt'
        }
        return response

    def _make_error():
        return 'HTTP Error 401: Unauthorized'
Beispiel #3
0
class LoginBackendDbusSSOFake(LoginBackend):

    def __init__(self, window_id, appname, help_text):
        super(LoginBackendDbusSSOFake, self).__init__()
        self.appname = appname
        self.help_text = help_text
        self._window_id = window_id
        self._fake_settings = FakeReviewSettings()

    @network_delay
    def login(self, username=None, password=None):
        response = self._fake_settings.get_setting('login_response')

        if response == "successful":
            self.emit("login-successful", self._return_credentials())
        elif response == "failed":
            self.emit("login-failed")
        elif response == "denied":
            self.cancel_login()

        return

    def login_or_register(self):
        #fake functionality for this is no different to fake login()
        self.login()
        return

    def _random_unicode_string(self, length):
        retval = ''
        for i in range(0, length):
            retval = retval + random.choice(string.letters + string.digits)
        return retval.decode('utf-8')

    def _return_credentials(self):
        c = dbus.Dictionary(
            {
              dbus.String(u'consumer_secret'): dbus.String(
                self._random_unicode_string(30)),
              dbus.String(u'token'): dbus.String(
                self._random_unicode_string(50)),
              dbus.String(u'consumer_key'): dbus.String(
                self._random_unicode_string(7)),
              dbus.String(u'name'): dbus.String('Ubuntu Software Center @ ' +
                self._random_unicode_string(6)),
              dbus.String(u'token_secret'): dbus.String(
                self._random_unicode_string(50))
             },
             signature=dbus.Signature('ss')
             )
        return c