~leonardr/launchpadlib/use-1.0

« back to all changes in this revision

Viewing changes to src/launchpadlib/tests/test_launchpad.py

  • Committer: Gavin Panella
  • Date: 2009-11-26 09:55:19 UTC
  • mfrom: (73.1.3 safe-cred-dir)
  • Revision ID: gavin.panella@canonical.com-20091126095519-1039tktb1flvvfjv
[r=allenap] In Launchpad.login_with(), create the launchpadlib_dir with secure (0700) permissions, or chmod existing directory to be secure. Previously no attempt was made to ensure security. Landed on behalf of Kees Cook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
        credentials_path = os.path.join(service_path, 'credentials')
120
120
        self.assertTrue(os.path.isdir(credentials_path))
121
121
 
 
122
    def test_dirs_created_are_changed_to_secure(self):
 
123
        launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
 
124
        # Verify a newly created-by-hand directory is insecure
 
125
        os.mkdir(launchpadlib_dir)
 
126
        os.chmod(launchpadlib_dir, 0755)
 
127
        self.assertTrue(os.path.isdir(launchpadlib_dir))
 
128
        statinfo = os.stat(launchpadlib_dir)
 
129
        mode = stat.S_IMODE(statinfo.st_mode)
 
130
        self.assertNotEqual(mode, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
 
131
        launchpad = NoNetworkLaunchpad.login_with(
 
132
            'not important', service_root='http://api.example.com/beta',
 
133
            launchpadlib_dir=launchpadlib_dir)
 
134
        # Verify the mode has been changed to 0700
 
135
        statinfo = os.stat(launchpadlib_dir)
 
136
        mode = stat.S_IMODE(statinfo.st_mode)
 
137
        self.assertEqual(mode, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
 
138
 
 
139
    def test_dirs_created_are_secure(self):
 
140
        launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
 
141
        launchpad = NoNetworkLaunchpad.login_with(
 
142
            'not important', service_root='http://api.example.com/beta',
 
143
            launchpadlib_dir=launchpadlib_dir)
 
144
        self.assertTrue(os.path.isdir(launchpadlib_dir))
 
145
        # Verify the mode is safe
 
146
        statinfo = os.stat(launchpadlib_dir)
 
147
        mode = stat.S_IMODE(statinfo.st_mode)
 
148
        self.assertEqual(mode, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
 
149
 
122
150
    def test_no_credentials_calls_get_token_and_login(self):
123
151
        # If no credentials are found, get_token_and_login() is called.
124
152
        service_root = 'http://api.example.com/beta'