Skip to content

Commit

Permalink
Fixes #34818 - Fix Upstream authentication autofill issue (#10076)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manisha15 committed May 10, 2022
1 parent 8b76c45 commit ea78e26
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 47 deletions.
Expand Up @@ -89,7 +89,7 @@ angular.module('Bastion.repositories').controller('RepositoryDetailsInfoControll
return deferred.promise;
};

$scope.save = function (repository, saveUpstreamAuth) {
$scope.save = function (repository) {
var deferred = $q.defer();
var fields = ['upstream_password', 'upstream_username', 'upstream_authentication_token', 'ansible_collection_auth_token', 'ansible_collection_auth_url', 'ansible_collection_requirements'];
if (repository.content_type === 'yum' && typeof repository.ignore_srpms !== 'undefined') {
Expand All @@ -99,13 +99,6 @@ angular.module('Bastion.repositories').controller('RepositoryDetailsInfoControll
repository['ignorable_content'] = [];
}
}

if (!saveUpstreamAuth) {
repository['upstream_username'] = null;
repository['upstream_password'] = null;
repository['upstream_authentication_token'] = null;
}

if ($scope.genericRemoteOptions && $scope.genericRemoteOptions !== []) {
$scope.genericRemoteOptions.forEach(function(option) {
if (option.type === "Array") {
Expand Down Expand Up @@ -141,6 +134,9 @@ angular.module('Bastion.repositories').controller('RepositoryDetailsInfoControll
repository[field] = null;
}
});
if (!repository['upstream_username']) {
repository['upstream_password'] = null;
}
repository.os_versions = $scope.osVersionsParam();
repository.$update(function (response) {
deferred.resolve(response);
Expand Down
Expand Up @@ -63,7 +63,7 @@ <h4 translate>Sync Settings</h4>
<dt ng-show="repository.content_type !== 'docker'" translate>Upstream URL</dt>
<dt ng-show="repository.content_type === 'docker'" translate>Registry URL</dt>
<dd bst-edit-text="repository.url"
on-save="save(repository, true)"
on-save="save(repository)"
readonly="product.redhat || denied('edit_products', product)">
</dd>

Expand Down Expand Up @@ -134,7 +134,7 @@ <h4 translate>Sync Settings</h4>
<dt translate>Ansible Collection Authorization</dt>
<dd bst-edit-custom="repository.ansible_collection_auth_exists"
readonly="denied('edit_products', product)"
on-save="save(repository, true)"
on-save="save(repository)"
formatter="ansibleAuthFilter"
formatter-options="repository"
deletable="repository.ansible_collection_auth_exists"
Expand Down Expand Up @@ -165,7 +165,7 @@ <h4 translate>Sync Settings</h4>
<dt translate>Upstream Authorization</dt>
<dd bst-edit-custom="repository.upstream_auth_exists"
readonly="denied('edit_products', product)"
on-save="save(repository, true)"
on-save="save(repository)"
formatter="upstreamPasswordFilter"
formatter-options="repository"
deletable="repository.upstream_auth_exists"
Expand All @@ -174,18 +174,17 @@ <h4 translate>Sync Settings</h4>
<input id="upstream_username"
name="upstream_username"
type="name"
autocomplete="off"
ng-model="repository.upstream_username"/>
<div translate>Upstream Password</div>
<input id="upstream_password"
<input id="upstream_password"
name="upstream_password"
type="password"
autocomplete="off"
type="{{ repository.upstream_password.length < 1 ? 'text': 'password' }}"
autocomplete="{{ (repository.upstream_username==null || repository.upstream_username=='') ? 'new-password' : '' }}"
ng-model="repository.upstream_password"/>
<div translate>Upstream Authentication Token</div>
<input id="upstream_authentication_token"
name="upstream_authentication_token"
type="password"
type="{{ repository.upstream_authentication_token.length < 1 ? 'text': 'password' }}"
autocomplete="off"
ng-model="repository.upstream_authentication_token"/>
</dd>
Expand Down
Expand Up @@ -224,7 +224,8 @@ <h4 translate> Sync Settings </h4>
<input id="upstream_password"
name="upstream_password"
ng-model="repository.upstream_password"
type="password"/>
type="password"
autocomplete="new-password"/>
<p class="help-block" translate>
Password of the upstream repository user for authentication. Leave empty if repository does not require authentication.
</p>
Expand Down
Expand Up @@ -125,34 +125,6 @@ describe('Controller: RepositoryDetailsInfoController', function() {
expect(Notification.setSuccessMessage).toHaveBeenCalledWith('Repository Saved.');
});

it('should ignore upstream auth on save unless specified', function() {
var repo = new Repository({
upstream_username: 'autofilled',
upstream_password: 'autofilled',
upstream_authentication_token: 'autofilled'
})

$scope.save(repo);

expect(repo.upstream_username).toBe(null);
expect(repo.upstream_password).toBe(null);
expect(repo.upstream_authentication_token).toBe(null);
});

it('should not ignore upstream auth on save unless specified', function() {
var repo = new Repository({
upstream_username: 'autofilled',
upstream_password: 'autofilled',
upstream_authentication_token: 'autofilled'
})

$scope.save(repo, true);

expect(repo.upstream_username).toBe('autofilled');
expect(repo.upstream_password).toBe('autofilled');
expect(repo.upstream_authentication_token).toBe('autofilled');
});

it('should clear out auth fields on save if blank', function() {
var repo = new Repository({
upstream_username: '',
Expand All @@ -162,7 +134,7 @@ describe('Controller: RepositoryDetailsInfoController', function() {
ansible_collection_auth_token: '',
})

$scope.save(repo, true);
$scope.save(repo);

expect(repo.upstream_username).toBe(null);
expect(repo.upstream_password).toBe(null);
Expand All @@ -180,7 +152,7 @@ describe('Controller: RepositoryDetailsInfoController', function() {
ansible_collection_auth_token: 'some_token',
})

$scope.save(repo, true);
$scope.save(repo);

expect(repo.upstream_username).not.toBe(null);
expect(repo.upstream_password).not.toBe(null);
Expand Down

0 comments on commit ea78e26

Please sign in to comment.