fix: bitwarden key could be an invalid username/secret
This commit is contained in:
parent
52a56476d3
commit
8b180e131e
6 changed files with 39 additions and 10 deletions
|
@ -42,23 +42,25 @@ class Annotator(Walk):
|
||||||
for variable in self.get_variables():
|
for variable in self.get_variables():
|
||||||
if not variable.bitwarden:
|
if not variable.bitwarden:
|
||||||
continue
|
continue
|
||||||
|
path = variable.path
|
||||||
if variable.type not in ["unix_user", "secret"]:
|
if variable.type not in ["unix_user", "secret"]:
|
||||||
msg = _('only "unix_user" or "secret" variable type can have "bitwarden" attribute, but "{0}" has type "{1}"')
|
msg = _('only "unix_user" or "secret" variable type can have "bitwarden" attribute, but "{0}" has type "{1}"')
|
||||||
raise DictConsistencyError(msg.format(variable.path, variable.type), 301, variable.xmlfiles)
|
raise DictConsistencyError(msg.format(path, variable.type), 301, variable.xmlfiles)
|
||||||
if variable.multi and variable.path not in self.objectspace.leaders:
|
if variable.multi and path not in self.objectspace.leaders:
|
||||||
msg = _('the variable "{0}" has attribute "bitwarden" but is a multi variable')
|
msg = _('the variable "{0}" has attribute "bitwarden" but is a multi variable')
|
||||||
raise DictConsistencyError(msg.format(variable.path), 302, variable.xmlfiles)
|
raise DictConsistencyError(msg.format(path), 302, variable.xmlfiles)
|
||||||
check_default_value = True
|
check_default_value = True
|
||||||
if variable.path in self.objectspace.followers:
|
if path in self.objectspace.followers:
|
||||||
leadership = variable.path.rsplit('.', 1)[0]
|
leadership = path.rsplit('.', 1)[0]
|
||||||
leader_path = self.objectspace.parents[leadership][0]
|
leader_path = self.objectspace.parents[leadership][0]
|
||||||
leader = self.objectspace.paths[leader_path]
|
leader = self.objectspace.paths[leader_path]
|
||||||
if leader.bitwarden:
|
if leader.bitwarden:
|
||||||
if variable.default:
|
if variable.default:
|
||||||
msg = _('the variable "{0}" is a follower and leader variable ("{1}") is also in Bitwarden so this variable could not have default value')
|
msg = _('the variable "{0}" is a follower and leader variable ("{1}") is also in Bitwarden so this variable could not have default value')
|
||||||
raise DictConsistencyError(msg.format(variable.path, leader_path), 303, variable.xmlfiles)
|
raise DictConsistencyError(msg.format(path, leader_path), 303, variable.xmlfiles)
|
||||||
check_default_value = False
|
check_default_value = False
|
||||||
if check_default_value and not variable.default:
|
if check_default_value and not variable.default:
|
||||||
msg = _('the variable "{0}" is in Bitwarden so should have default value')
|
msg = _('the variable "{0}" is in Bitwarden so should have default value')
|
||||||
raise DictConsistencyError(msg.format(variable.path), 304, variable.xmlfiles)
|
raise DictConsistencyError(msg.format(path), 304, variable.xmlfiles)
|
||||||
self.objectspace.informations.add(variable.path, "bitwarden", True)
|
self.objectspace.informations.add(path, "bitwarden", True)
|
||||||
|
self.objectspace.properties.add(path, "novalidator", True)
|
||||||
|
|
|
@ -75,9 +75,9 @@ class RougailUserDataBitwarden:
|
||||||
if option.isleader():
|
if option.isleader():
|
||||||
leader_values = []
|
leader_values = []
|
||||||
self.leader_informations[path] = []
|
self.leader_informations[path] = []
|
||||||
for val in option.value.get():
|
values = option.value.get()
|
||||||
|
for val in values:
|
||||||
names, values = self.get_values(path, type_, val, allow_multiple=True)
|
names, values = self.get_values(path, type_, val, allow_multiple=True)
|
||||||
print(names, values)
|
|
||||||
if isinstance(values, list):
|
if isinstance(values, list):
|
||||||
leader_values.extend(values)
|
leader_values.extend(values)
|
||||||
self.leader_informations[path].extend(names)
|
self.leader_informations[path].extend(names)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"errors": [],
|
||||||
|
"warnings": []
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.username": "up_secret_error_1",
|
||||||
|
"rougail.secret": "up_secret_error_pass_1"
|
||||||
|
}
|
14
tests/structures/2_username_secret_invalid/00-base.yml
Normal file
14
tests/structures/2_username_secret_invalid/00-base.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
username:
|
||||||
|
description: the username
|
||||||
|
type: unix_user
|
||||||
|
default: UP SECRET 1
|
||||||
|
bitwarden: true
|
||||||
|
|
||||||
|
secret:
|
||||||
|
description: the secret
|
||||||
|
type: secret
|
||||||
|
default: UP SECRET 1
|
||||||
|
bitwarden: true
|
|
@ -60,6 +60,11 @@ def test_dictionaries_2_username_secret():
|
||||||
_test_dictionaries(test_dir / '2_username_secret')
|
_test_dictionaries(test_dir / '2_username_secret')
|
||||||
|
|
||||||
|
|
||||||
|
def test_dictionaries_2_username_secret_invalid():
|
||||||
|
"tests the output"
|
||||||
|
_test_dictionaries(test_dir / '2_username_secret_invalid')
|
||||||
|
|
||||||
|
|
||||||
def test_dictionaries_3_leadership_secret():
|
def test_dictionaries_3_leadership_secret():
|
||||||
"tests the output"
|
"tests the output"
|
||||||
_test_dictionaries(test_dir / '3_leadership_secret')
|
_test_dictionaries(test_dir / '3_leadership_secret')
|
||||||
|
|
Loading…
Reference in a new issue