-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15048 from netbox-community/develop
Release v3.7.2
- Loading branch information
Showing
73 changed files
with
30,082 additions
and
2,466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
from django.test import TestCase | ||
|
||
from core.models import DataSource | ||
from extras.choices import ObjectChangeActionChoices | ||
from netbox.constants import CENSOR_TOKEN, CENSOR_TOKEN_CHANGED | ||
|
||
|
||
class DataSourceChangeLoggingTestCase(TestCase): | ||
|
||
def test_password_added_on_create(self): | ||
datasource = DataSource.objects.create( | ||
name='Data Source 1', | ||
type='git', | ||
source_url='http://localhost/', | ||
parameters={ | ||
'username': 'jeff', | ||
'password': 'foobar123', | ||
} | ||
) | ||
|
||
objectchange = datasource.to_objectchange(ObjectChangeActionChoices.ACTION_CREATE) | ||
self.assertIsNone(objectchange.prechange_data) | ||
self.assertEqual(objectchange.postchange_data['parameters']['username'], 'jeff') | ||
self.assertEqual(objectchange.postchange_data['parameters']['password'], CENSOR_TOKEN_CHANGED) | ||
|
||
def test_password_added_on_update(self): | ||
datasource = DataSource.objects.create( | ||
name='Data Source 1', | ||
type='git', | ||
source_url='http://localhost/' | ||
) | ||
datasource.snapshot() | ||
|
||
# Add a blank password | ||
datasource.parameters = { | ||
'username': 'jeff', | ||
'password': '', | ||
} | ||
|
||
objectchange = datasource.to_objectchange(ObjectChangeActionChoices.ACTION_UPDATE) | ||
self.assertIsNone(objectchange.prechange_data['parameters']) | ||
self.assertEqual(objectchange.postchange_data['parameters']['username'], 'jeff') | ||
self.assertEqual(objectchange.postchange_data['parameters']['password'], '') | ||
|
||
# Add a password | ||
datasource.parameters = { | ||
'username': 'jeff', | ||
'password': 'foobar123', | ||
} | ||
|
||
objectchange = datasource.to_objectchange(ObjectChangeActionChoices.ACTION_UPDATE) | ||
self.assertEqual(objectchange.postchange_data['parameters']['username'], 'jeff') | ||
self.assertEqual(objectchange.postchange_data['parameters']['password'], CENSOR_TOKEN_CHANGED) | ||
|
||
def test_password_changed(self): | ||
datasource = DataSource.objects.create( | ||
name='Data Source 1', | ||
type='git', | ||
source_url='http://localhost/', | ||
parameters={ | ||
'username': 'jeff', | ||
'password': 'password1', | ||
} | ||
) | ||
datasource.snapshot() | ||
|
||
# Change the password | ||
datasource.parameters['password'] = 'password2' | ||
|
||
objectchange = datasource.to_objectchange(ObjectChangeActionChoices.ACTION_UPDATE) | ||
self.assertEqual(objectchange.prechange_data['parameters']['username'], 'jeff') | ||
self.assertEqual(objectchange.prechange_data['parameters']['password'], CENSOR_TOKEN) | ||
self.assertEqual(objectchange.postchange_data['parameters']['username'], 'jeff') | ||
self.assertEqual(objectchange.postchange_data['parameters']['password'], CENSOR_TOKEN_CHANGED) | ||
|
||
def test_password_removed_on_update(self): | ||
datasource = DataSource.objects.create( | ||
name='Data Source 1', | ||
type='git', | ||
source_url='http://localhost/', | ||
parameters={ | ||
'username': 'jeff', | ||
'password': 'foobar123', | ||
} | ||
) | ||
datasource.snapshot() | ||
|
||
objectchange = datasource.to_objectchange(ObjectChangeActionChoices.ACTION_UPDATE) | ||
self.assertEqual(objectchange.prechange_data['parameters']['username'], 'jeff') | ||
self.assertEqual(objectchange.prechange_data['parameters']['password'], CENSOR_TOKEN) | ||
self.assertEqual(objectchange.postchange_data['parameters']['username'], 'jeff') | ||
self.assertEqual(objectchange.postchange_data['parameters']['password'], CENSOR_TOKEN) | ||
|
||
# Remove the password | ||
datasource.parameters['password'] = '' | ||
|
||
objectchange = datasource.to_objectchange(ObjectChangeActionChoices.ACTION_UPDATE) | ||
self.assertEqual(objectchange.prechange_data['parameters']['username'], 'jeff') | ||
self.assertEqual(objectchange.prechange_data['parameters']['password'], CENSOR_TOKEN) | ||
self.assertEqual(objectchange.postchange_data['parameters']['username'], 'jeff') | ||
self.assertEqual(objectchange.postchange_data['parameters']['password'], '') | ||
|
||
def test_password_not_modified(self): | ||
datasource = DataSource.objects.create( | ||
name='Data Source 1', | ||
type='git', | ||
source_url='http://localhost/', | ||
parameters={ | ||
'username': 'username1', | ||
'password': 'foobar123', | ||
} | ||
) | ||
datasource.snapshot() | ||
|
||
# Remove the password | ||
datasource.parameters['username'] = 'username2' | ||
|
||
objectchange = datasource.to_objectchange(ObjectChangeActionChoices.ACTION_UPDATE) | ||
self.assertEqual(objectchange.prechange_data['parameters']['username'], 'username1') | ||
self.assertEqual(objectchange.prechange_data['parameters']['password'], CENSOR_TOKEN) | ||
self.assertEqual(objectchange.postchange_data['parameters']['username'], 'username2') | ||
self.assertEqual(objectchange.postchange_data['parameters']['password'], CENSOR_TOKEN) |
Oops, something went wrong.