def test_token_set(self):
     """
     The user's API token can be set, and will be saved in the local
     state.
     """
     self.useFixture(JenkinsConfiguredAdmin(self.fakes))
     self.assertEqual("abc", self.credentials.token("abc"))
     self.assertEqual("abc", self.credentials.token())
     self.assertThat(paths.ADMIN_TOKEN, FileContains("abc"))
     self.assertThat(paths.ADMIN_TOKEN, HasOwnership(0, 0))
     self.assertThat(paths.ADMIN_TOKEN, HasPermissions("0600"))
Example #2
0
    def test_configure_admin_custom_password(self):
        """
        If a password is provided, it's used to configure the admin user.
        """
        self.fakes.juju.config["password"] = "******"
        script = UPDATE_PASSWORD_SCRIPT.format(username="******", password="******")
        self.fakes.jenkins.scripts[script] = ""

        self.users.configure_admin()

        self.assertThat(paths.ADMIN_PASSWORD, FileContains("x"))
        self.assertThat(paths.ADMIN_PASSWORD, HasOwnership(0, 0))
        self.assertThat(paths.ADMIN_PASSWORD, HasPermissions("0600"))

        self.assertThat(paths.LAST_EXEC, FileContains("2.0.0\n"))
        self.assertThat(paths.LAST_EXEC, HasOwnership(123, 456))
Example #3
0
 def test_chmod(self):
     self.fs.add("/foo")
     with open("/foo", "w") as fd:
         fd.write("")
     os.chmod("/foo", 0o600)
     self.assertThat("/foo", HasPermissions("0600"))
    def test_successful_export(self):
        self.export_login("exported", expect_success=True)

        # Verify that the exported login is only readable by the owner
        self.assertThat("exported", HasPermissions("0400"))
Example #5
0
 def test_match(self):
     tempdir = self.mkdtemp()
     filename = os.path.join(tempdir, 'filename')
     self.touch(filename)
     permissions = oct(os.stat(filename).st_mode)[-4:]
     self.assertThat(filename, HasPermissions(permissions))