Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #41

Merged
merged 5 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:

- name: Build
env:
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || 'USER' }}
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || 'user' }}
BUILD_NR: ${{ github.run_number }}
PLATFORM: ${{ matrix.platforms }}
VERSION: ${{ needs.Setup.outputs.version }}
Expand All @@ -79,7 +79,7 @@ jobs:

- name: Test
env:
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || 'USER' }}
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || 'user' }}
BUILD_NR: ${{ github.run_number }}
PLATFORM: ${{ matrix.platforms }}
VERSION: ${{ needs.Setup.outputs.version }}
Expand All @@ -99,13 +99,13 @@ jobs:
if: github.event_name == 'release'
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKER_HUB_USERNAME || 'USER' }}
username: ${{ vars.DOCKER_HUB_USERNAME || 'user' }}
password: ${{ secrets.DOCKER_HUB_DEPLOY_KEY }}

- name: Push Images
if: github.event_name == 'release'
env:
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || 'USER' }}
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || 'user' }}
BUILD_NR: ${{ github.run_number }}
PLATFORM: ${{ matrix.platforms }}
VERSION: ${{ needs.Setup.outputs.version }}
Expand Down Expand Up @@ -135,12 +135,12 @@ jobs:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKER_HUB_USERNAME || 'USER' }}
username: ${{ vars.DOCKER_HUB_USERNAME || 'user' }}
password: ${{ secrets.DOCKER_HUB_DEPLOY_KEY }}

- name: Create and push shared manifest
env:
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || 'USER' }}
DOCKER_USER: ${{ vars.DOCKER_HUB_USERNAME || 'user' }}
BUILD_NR: ${{ github.run_number }}
VERSION: ${{ needs.Setup.outputs.version }}
run: |
Expand Down
12 changes: 10 additions & 2 deletions porkbun_ddns/porkbun_ddns.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,16 @@ def get_public_ips(self) -> list:
else:
if self.ipv4:
try:
public_ips.append(urllib.request.urlopen(
'https://v4.ident.me').read().decode('utf8'))
response = urllib.request.urlopen('https://v4.ident.me')
if response.getcode() == 200:
public_ips.append(response.read().decode('utf-8'))
else:
logger.warning("Failed to retrieve IPv4 Address! HTTP status code: {}".format(response.code()))
alternative_response = urllib.request.urlopen('https://api.ipify.org/')
if alternative_response.getcode() == 200:
public_ips.append(alternative_response.read().decode('utf-8'))
else:
logger.warning("Failed to retrieve IPv4 Address! HTTP status code: {}".format(response.code()))
except URLError:
logger.warning("Can't reach IPv4 Address! Check IPv4 connectivity!")
if self.ipv6:
Expand Down
19 changes: 18 additions & 1 deletion porkbun_ddns/test/test_porkbun_ddns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from unittest.mock import patch
from unittest.mock import patch, MagicMock
from ..porkbun_ddns import PorkbunDDNS, PorkbunDDNS_Error
import logging

Expand Down Expand Up @@ -159,6 +159,23 @@ def test_record_overwrite_alias_and_cname(self, mocker=None):
'INFO:porkbun_ddns:Creating AAAA-Record for my-domain.local with content: '
'0000:0000:0000:0000:0000:0000:0000:0001, Status: SUCCESS'])

@patch('urllib.request.urlopen')
def test_urlopen_returns_500(self, mock_urlopen):
# Set up the mock to return a response with status code 500
mock_response = MagicMock()
mock_response.getcode.return_value = 500
mock_urlopen.return_value = mock_response

# Instantiate your class or call the method that uses urllib.request.urlopen()
porkbun_ddns = PorkbunDDNS(valid_config, domain='example.com', ipv4=True, ipv6=False)

# Now when you call the method that uses urllib.request.urlopen(), it will get the mocked response
with self.assertRaises(PorkbunDDNS_Error) as context:
porkbun_ddns.get_public_ips()

# Verify that the exception has the expected error message
self.assertEqual(str(context.exception), 'Failed to obtain IP Addresses!')


if __name__ == '__main__':
unittest.main()
Loading