def test_check_min_permissions(self): filesystem.chmod(self.probe_path, 0o744) self.assertTrue(filesystem.has_min_permissions(self.probe_path, 0o744)) filesystem.chmod(self.probe_path, 0o700) self.assertFalse(filesystem.has_min_permissions(self.probe_path, 0o744)) filesystem.chmod(self.probe_path, 0o741) self.assertFalse(filesystem.has_min_permissions(self.probe_path, 0o744))
def common_perform_test(self, achalls, vhosts): """Tests perform with the given achalls.""" challenge_dir = self.http.challenge_dir self.assertIs(os.path.exists(challenge_dir), False) for achall in achalls: self.http.add_chall(achall) expected_response = [ achall.response(self.account_key) for achall in achalls ] self.assertEqual(self.http.perform(), expected_response) self.assertIs(os.path.isdir(self.http.challenge_dir), True) self.assertIs( filesystem.has_min_permissions(self.http.challenge_dir, 0o755), True) self._test_challenge_conf() for achall in achalls: self._test_challenge_file(achall) for vhost in vhosts: matches = self.config.parser.find_dir("Include", self.http.challenge_conf_pre, vhost.path) self.assertEqual(len(matches), 1) matches = self.config.parser.find_dir( "Include", self.http.challenge_conf_post, vhost.path) self.assertEqual(len(matches), 1) self.assertIs(os.path.exists(challenge_dir), True)
def _test_challenge_file(self, achall): name = os.path.join(self.http.challenge_dir, achall.chall.encode("token")) validation = achall.validation(self.account_key) self.assertTrue(filesystem.has_min_permissions(name, 0o644)) with open(name, 'rb') as f: self.assertEqual(f.read(), validation.encode())