mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-22 11:38:45 -06:00
Compare commits
2 Commits
15801-vlan
...
20902-git-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7eedefb2df | ||
|
|
339ad455e4 |
@@ -102,7 +102,10 @@ class GitBackend(DataBackend):
|
|||||||
clone_args['pool_manager'] = ProxyPoolManager(self.socks_proxy)
|
clone_args['pool_manager'] = ProxyPoolManager(self.socks_proxy)
|
||||||
|
|
||||||
if self.url_scheme in ('http', 'https'):
|
if self.url_scheme in ('http', 'https'):
|
||||||
if self.params.get('username'):
|
# Only pass explicit credentials if URL doesn't already contain embedded username
|
||||||
|
# to avoid credential conflicts
|
||||||
|
parsed_url = urlparse(self.url)
|
||||||
|
if not parsed_url.username and self.params.get('username'):
|
||||||
clone_args.update(
|
clone_args.update(
|
||||||
{
|
{
|
||||||
"username": self.params.get('username'),
|
"username": self.params.get('username'),
|
||||||
|
|||||||
59
netbox/core/tests/test_data_backends.py
Normal file
59
netbox/core/tests/test_data_backends.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from core.data_backends import GitBackend
|
||||||
|
|
||||||
|
|
||||||
|
class GitBackendCredentialTests(TestCase):
|
||||||
|
|
||||||
|
def _get_clone_kwargs(self, url, **params):
|
||||||
|
backend = GitBackend(url=url, **params)
|
||||||
|
|
||||||
|
with patch('dulwich.porcelain.clone') as mock_clone, \
|
||||||
|
patch('dulwich.porcelain.NoneStream'):
|
||||||
|
try:
|
||||||
|
with backend.fetch():
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if mock_clone.called:
|
||||||
|
return mock_clone.call_args.kwargs
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def test_url_with_embedded_username_skips_explicit_credentials(self):
|
||||||
|
kwargs = self._get_clone_kwargs(
|
||||||
|
url='https://myuser@bitbucket.org/workspace/repo.git',
|
||||||
|
username='myuser',
|
||||||
|
password='my-api-key'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(kwargs.get('username'), None)
|
||||||
|
self.assertEqual(kwargs.get('password'), None)
|
||||||
|
|
||||||
|
def test_url_without_embedded_username_passes_explicit_credentials(self):
|
||||||
|
kwargs = self._get_clone_kwargs(
|
||||||
|
url='https://bitbucket.org/workspace/repo.git',
|
||||||
|
username='myuser',
|
||||||
|
password='my-api-key'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(kwargs.get('username'), 'myuser')
|
||||||
|
self.assertEqual(kwargs.get('password'), 'my-api-key')
|
||||||
|
|
||||||
|
def test_url_with_embedded_username_no_explicit_credentials(self):
|
||||||
|
kwargs = self._get_clone_kwargs(
|
||||||
|
url='https://myuser@bitbucket.org/workspace/repo.git'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(kwargs.get('username'), None)
|
||||||
|
self.assertEqual(kwargs.get('password'), None)
|
||||||
|
|
||||||
|
def test_public_repo_no_credentials(self):
|
||||||
|
kwargs = self._get_clone_kwargs(
|
||||||
|
url='https://github.com/public/repo.git'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(kwargs.get('username'), None)
|
||||||
|
self.assertEqual(kwargs.get('password'), None)
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
{% block extra_controls %}
|
{% block extra_controls %}
|
||||||
{% include 'ipam/inc/toggle_available.html' %}
|
{% include 'ipam/inc/toggle_available.html' %}
|
||||||
|
{% include 'ipam/inc/max_depth.html' %}
|
||||||
|
{% include 'ipam/inc/max_length.html' %}
|
||||||
{% if perms.ipam.add_prefix and first_available_prefix %}
|
{% if perms.ipam.add_prefix and first_available_prefix %}
|
||||||
<a href="{% url 'ipam:prefix_add' %}?prefix={{ first_available_prefix }}" class="btn btn-primary">
|
<a href="{% url 'ipam:prefix_add' %}?prefix={{ first_available_prefix }}" class="btn btn-primary">
|
||||||
<i class="mdi mdi-plus-thick" aria-hidden="true"></i> {% trans "Add Prefix" %}
|
<i class="mdi mdi-plus-thick" aria-hidden="true"></i> {% trans "Add Prefix" %}
|
||||||
|
|||||||
20
netbox/templates/ipam/inc/max_depth.html
Normal file
20
netbox/templates/ipam/inc/max_depth.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
{% load helpers %}
|
||||||
|
|
||||||
|
<div class="dropdown">
|
||||||
|
<button class="btn btn-outline-secondary dropdown-toggle" type="button" id="max_depth" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||||
|
{% trans "Max Depth" %}{% if "depth__lte" in request.GET %}: {{ request.GET.depth__lte }}{% endif %}
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="max_depth">
|
||||||
|
{% if request.GET.depth__lte %}
|
||||||
|
<li>
|
||||||
|
<a class="dropdown-item" href="{{ request.path }}{% querystring request depth__lte=None page=1 %}">{% trans "Clear" %}</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% for i in 16|as_range %}
|
||||||
|
<li><a class="dropdown-item" href="{{ request.path }}{% querystring request depth__lte=i page=1 %}">
|
||||||
|
{{ i }} {% if request.GET.depth__lte == i %}<i class="mdi mdi-check-bold"></i>{% endif %}
|
||||||
|
</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
20
netbox/templates/ipam/inc/max_length.html
Normal file
20
netbox/templates/ipam/inc/max_length.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
{% load helpers %}
|
||||||
|
|
||||||
|
<div class="dropdown">
|
||||||
|
<button class="btn btn-outline-secondary dropdown-toggle" type="button" id="max_length" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||||
|
{% trans "Max Length" %}{% if "mask_length__lte" in request.GET %}: {{ request.GET.mask_length__lte }}{% endif %}
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="max_length">
|
||||||
|
{% if request.GET.mask_length__lte %}
|
||||||
|
<li>
|
||||||
|
<a class="dropdown-item" href="{{ request.path }}{% querystring request mask_length__lte=None page=1 %}">{% trans "Clear" %}</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% for i in "4,8,12,16,20,24,28,32,40,48,56,64"|split %}
|
||||||
|
<li><a class="dropdown-item" href="{{ request.path }}{% querystring request mask_length__lte=i page=1 %}">
|
||||||
|
{{ i }} {% if request.GET.mask_length__lte == i %}<i class="mdi mdi-check-bold"></i>{% endif %}
|
||||||
|
</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
{% block extra_controls %}
|
{% block extra_controls %}
|
||||||
{% include 'ipam/inc/toggle_available.html' %}
|
{% include 'ipam/inc/toggle_available.html' %}
|
||||||
|
{% include 'ipam/inc/max_depth.html' %}
|
||||||
|
{% include 'ipam/inc/max_length.html' %}
|
||||||
{% if perms.ipam.add_prefix and first_available_prefix %}
|
{% if perms.ipam.add_prefix and first_available_prefix %}
|
||||||
<a href="{% url 'ipam:prefix_add' %}?prefix={{ first_available_prefix }}&vrf={{ object.vrf.pk }}&site={{ object.site.pk }}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}" class="btn btn-primary">
|
<a href="{% url 'ipam:prefix_add' %}?prefix={{ first_available_prefix }}&vrf={{ object.vrf.pk }}&site={{ object.site.pk }}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}" class="btn btn-primary">
|
||||||
<i class="mdi mdi-plus-thick" aria-hidden="true"></i> {% trans "Add Prefix" %}
|
<i class="mdi mdi-plus-thick" aria-hidden="true"></i> {% trans "Add Prefix" %}
|
||||||
|
|||||||
@@ -6,38 +6,6 @@
|
|||||||
<button class="btn btn-outline-secondary toggle-depth" type="button">
|
<button class="btn btn-outline-secondary toggle-depth" type="button">
|
||||||
{% trans "Hide Depth Indicators" %}
|
{% trans "Hide Depth Indicators" %}
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown">
|
{% include 'ipam/inc/max_depth.html' %}
|
||||||
<button class="btn btn-outline-secondary dropdown-toggle" type="button" id="max_depth" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
{% include 'ipam/inc/max_length.html' %}
|
||||||
{% trans "Max Depth" %}{% if "depth__lte" in request.GET %}: {{ request.GET.depth__lte }}{% endif %}
|
|
||||||
</button>
|
|
||||||
<ul class="dropdown-menu" aria-labelledby="max_depth">
|
|
||||||
{% if request.GET.depth__lte %}
|
|
||||||
<li>
|
|
||||||
<a class="dropdown-item" href="{% url 'ipam:prefix_list' %}{% querystring request depth__lte=None page=1 %}">{% trans "Clear" %}</a>
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
{% for i in 16|as_range %}
|
|
||||||
<li><a class="dropdown-item" href="{% url 'ipam:prefix_list' %}{% querystring request depth__lte=i page=1 %}">
|
|
||||||
{{ i }} {% if request.GET.depth__lte == i %}<i class="mdi mdi-check-bold"></i>{% endif %}
|
|
||||||
</a></li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div class="dropdown">
|
|
||||||
<button class="btn btn-outline-secondary dropdown-toggle" type="button" id="max_length" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
|
||||||
{% trans "Max Length" %}{% if "mask_length__lte" in request.GET %}: {{ request.GET.mask_length__lte }}{% endif %}
|
|
||||||
</button>
|
|
||||||
<ul class="dropdown-menu" aria-labelledby="max_length">
|
|
||||||
{% if request.GET.mask_length__lte %}
|
|
||||||
<li>
|
|
||||||
<a class="dropdown-item" href="{% url 'ipam:prefix_list' %}{% querystring request mask_length__lte=None page=1 %}">{% trans "Clear" %}</a>
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
{% for i in "4,8,12,16,20,24,28,32,40,48,56,64"|split %}
|
|
||||||
<li><a class="dropdown-item" href="{% url 'ipam:prefix_list' %}{% querystring request mask_length__lte=i page=1 %}">
|
|
||||||
{{ i }} {% if request.GET.mask_length__lte == i %}<i class="mdi mdi-check-bold"></i>{% endif %}
|
|
||||||
</a></li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user