Support passwordless Pi-hole authentication and UI settings
All checks were successful
Test and publish Homegate / publish (push) Successful in 12m49s
Test and publish Homegate / checks (push) Successful in 29s

This commit is contained in:
2026-10-14 18:12:10 +03:00
parent a83d897b70
commit b305cc1ba8
13 changed files with 130 additions and 33 deletions

View File

@@ -112,6 +112,47 @@ class SetupTests(unittest.TestCase):
self.assertEqual(self.request('/api/settings', self.settings)[0], 409)
self.assertEqual(self.connections.read_bytes(), before)
def test_passwordless_pihole_can_be_enabled_and_password_restored(self):
state = self.install()
settings = copy.deepcopy(self.settings)
settings['revision'] = state['revision']
settings['connections']['pihole_password'] = ''
code, state, _ = self.request('/api/settings', settings)
self.assertEqual(code, 200)
self.assertTrue(state['connections']['pihole_password_set'])
settings['revision'] = state['revision']
settings['connections']['clear_pihole_password'] = True
code, state, _ = self.request('/api/settings', settings)
self.assertEqual(code, 200)
self.assertFalse(state['connections']['pihole_password_set'])
stored = h.read_json(self.connections)
self.assertEqual(stored['pihole_password'], '')
self.assertEqual(stored['npm_password'], 'test-npm-secret')
self.assertNotIn('clear_pihole_password', stored)
with patch.dict(os.environ, {'HOMEGATE_CONNECTIONS': str(self.connections)}, clear=True), patch.object(h, 'NPM'), patch.object(h, 'PiHole') as dns, patch.object(h, 'reconcile'):
h.cycle(settings['config'], self.root, None, {})
dns.return_value.login.assert_called_once_with('')
settings['revision'] = state['revision']
settings['connections'].update(clear_pihole_password=False, pihole_password='new-password')
code, state, _ = self.request('/api/settings', settings)
self.assertEqual(code, 200)
self.assertTrue(state['connections']['pihole_password_set'])
self.assertEqual(h.read_json(self.connections)['pihole_password'], 'new-password')
def test_first_setup_accepts_passwordless_pihole(self):
self.settings['connections'].update(pihole_password='', clear_pihole_password=True)
state = self.install()
self.assertFalse(state['connections']['pihole_password_set'])
self.assertEqual(h.read_json(self.connections)['pihole_password'], '')
def test_invalid_password_clear_flag_does_not_change_credentials(self):
state = self.install()
self.settings['revision'] = state['revision']
self.settings['connections']['clear_pihole_password'] = 'true'
before = self.connections.read_bytes()
self.assertEqual(self.request('/api/settings', self.settings)[0], 400)
self.assertEqual(self.connections.read_bytes(), before)
def test_acl_host_and_same_origin_work_without_fixed_origin(self):
self.connect()
self.assertEqual(self.request(peer='8.8.8.8')[0], 403)