generated from datalad/datalad-extension-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49eab46
commit 43c885c
Showing
4 changed files
with
24 additions
and
34 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -80,7 +80,7 @@ def test_compute_remote_main(tmp_path, datalad_cfg, monkeypatch, trusted): | |
monkeypatch.setenv('GNUPGHOME', str(gpg_homedir)) | ||
|
||
# Generate a keypair | ||
keyid = create_keypair(gpg_homedir) | ||
keyid = import_keypair(gpg_homedir) | ||
|
||
datalad_cfg.add('datalad.trusted-keys', keyid, where='global') | ||
|
||
|
@@ -148,43 +148,33 @@ def test_compute_remote_main(tmp_path, datalad_cfg, monkeypatch, trusted): | |
assert (tmp_path / 'remade.txt').read_text().strip() == 'content: some_string' | ||
|
||
|
||
def create_keypair(gpg_dir: Path, name: bytes = b'Test User'): | ||
def import_keypair(gpg_dir: Path, stem: str = 'test_key') -> str: | ||
gpg_dir.mkdir(parents=True, exist_ok=True) | ||
gpg_dir.chmod(0o700) | ||
private_keys_dir = gpg_dir / 'private-keys-v1.d' | ||
private_keys_dir.mkdir(exist_ok=True) | ||
private_keys_dir.chmod(0o700) | ||
template = b""" | ||
Key-Type: RSA | ||
Key-Length: 4096 | ||
Subkey-Type: RSA | ||
Subkey-Length: 4096 | ||
Name-Real: $NAME | ||
Name-Email: [email protected] | ||
Expire-Date: 0 | ||
%no-protection | ||
#%transient-key | ||
%commit | ||
""" | ||
script = template.replace(b'$NAME', name) | ||
|
||
key_dir = Path(__file__).parent / 'keys' | ||
|
||
# Unset $HOME to prevent accidental changes to the user's keyring | ||
environment = {'HOME': '/dev/null'} | ||
|
||
subprocess.run( | ||
[ # noqa: S607 | ||
'gpg', | ||
'--batch', | ||
'--homedir', | ||
str(gpg_dir), | ||
'--gen-key', | ||
'--keyid-format', | ||
'long', | ||
], | ||
input=script, | ||
capture_output=True, | ||
check=True, | ||
env=environment, | ||
) | ||
for key_file in (stem, stem + '.pub'): | ||
subprocess.run( | ||
[ # noqa: S607 | ||
'gpg', | ||
'--batch', | ||
'--homedir', | ||
str(gpg_dir), | ||
'--import', | ||
str(key_dir / key_file), | ||
], | ||
capture_output=True, | ||
check=True, | ||
env=environment, | ||
) | ||
|
||
result = subprocess.run( | ||
[ # noqa: S607 | ||
'gpg', | ||
|
@@ -199,6 +189,6 @@ def create_keypair(gpg_dir: Path, name: bytes = b'Test User'): | |
env=environment, | ||
) | ||
return re.findall( | ||
r'(?m)sec.*rsa4096/([A-Z0-9]+).*\n.*\n.*' + name.decode(), | ||
r'(?m)sec.*rsa4096/([A-Z0-9]+).*\n', | ||
result.stdout.decode(), | ||
)[0] |
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