~mandel/ubuntu-sso-client/pinned-certs

« back to all changes in this revision

Viewing changes to ubuntuone/oauthdesktop/tests/test_main.py

  • Committer: natalia.bidart at canonical
  • Date: 2010-06-08 11:54:48 UTC
  • Revision ID: natalia.bidart@canonical.com-20100608115448-aqeiwm4ki1nljaw1
Built correct structure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# test_main - tests for ubuntuone.oauthdesktop.main
 
2
#
 
3
# Author: Stuart Langridge <stuart.langridge@canonical.com>
 
4
#
 
5
# Copyright 2009 Canonical Ltd.
 
6
#
 
7
# This program is free software: you can redistribute it and/or modify it
 
8
# under the terms of the GNU General Public License version 3, as published
 
9
# by the Free Software Foundation.
 
10
#
 
11
# This program is distributed in the hope that it will be useful, but
 
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
14
# PURPOSE.  See the GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License along
 
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
"""Tests for the OAuth client code for StorageFS."""
 
19
 
 
20
import os, StringIO
 
21
from mocker import MockerTestCase
 
22
from ubuntuone.oauthdesktop import config
 
23
from ubuntuone.oauthdesktop.main import LoginProcessor, BadRealmError
 
24
 
 
25
class Realm(MockerTestCase):
 
26
    """Test the realm handling finder"""
 
27
 
 
28
    def test_invalid_realm(self):
 
29
        """Are invalid realms rejected?"""
 
30
                
 
31
        login = LoginProcessor(None, use_libnotify=False)
 
32
        self.assertRaises(BadRealmError, login.login, "bad realm", "key")
 
33
 
 
34
    def test_realms(self):
 
35
        """Are realm URLs correctly retrieved from the config?"""
 
36
        
 
37
        # mock that tmp config file exists
 
38
        tmp_config_file = os.path.realpath(os.path.join(
 
39
          os.path.split(config.__file__)[0], "../../data/oauth_urls"
 
40
        ))
 
41
        osp = self.mocker.replace("os.path")
 
42
        osp.isfile(tmp_config_file)
 
43
        self.mocker.result(True)
 
44
        
 
45
        sio = StringIO.StringIO("""[default]
 
46
request_token_url = /rtu-default
 
47
user_authorisation_url = /uau-default
 
48
access_token_url = /atu-default
 
49
consumer_secret = foo-default
 
50
 
 
51
[http://localhost]
 
52
request_token_url = /rtu-localhost
 
53
user_authorisation_url = /uau-localhost
 
54
access_token_url = /atu-localhost
 
55
consumer_secret = foo-localhost
 
56
 
 
57
[http://ubuntuone.com]
 
58
request_token_url = /rtu-ubuntuone
 
59
user_authorisation_url = /uau-ubuntuone
 
60
access_token_url = /atu-ubuntuone
 
61
consumer_secret = foo-ubuntuone
 
62
 
 
63
""")
 
64
        mock_open = self.mocker.replace(open)
 
65
        mock_open(tmp_config_file)
 
66
        self.mocker.result(sio)
 
67
        
 
68
        self.mocker.replay()
 
69
        
 
70
        login = LoginProcessor(None, use_libnotify=False)
 
71
        
 
72
        # are localhost:XXXX URLs correctly fetched?
 
73
        (rtu, uau, atu, cs) = login.get_config_urls("http://localhost:9876")
 
74
        self.assertEqual(rtu, "http://localhost:9876/rtu-localhost")
 
75
        self.assertEqual(uau, "http://localhost:9876/uau-localhost")
 
76
        self.assertEqual(atu, "http://localhost:9876/atu-localhost")
 
77
        self.assertEqual(cs, "foo-localhost")
 
78
 
 
79
        # is a URL specifically in the config correctly fetched?
 
80
        (rtu, uau, atu, cs) = login.get_config_urls("http://ubuntuone.com")
 
81
        self.assertEqual(rtu, "http://ubuntuone.com/rtu-ubuntuone")
 
82
        self.assertEqual(uau, "http://ubuntuone.com/uau-ubuntuone")
 
83
        self.assertEqual(atu, "http://ubuntuone.com/atu-ubuntuone")
 
84
        self.assertEqual(cs, "foo-ubuntuone")
 
85
 
 
86
        # is a URL not in the config correctly fetched as default?
 
87
        (rtu, uau, atu, cs) = login.get_config_urls("http://other.example.net")
 
88
        self.assertEqual(rtu, "http://other.example.net/rtu-default")
 
89
        self.assertEqual(uau, "http://other.example.net/uau-default")
 
90
        self.assertEqual(atu, "http://other.example.net/atu-default")
 
91
        self.assertEqual(cs, "foo-default")
 
92
 
 
93