Skip to content

Commit f097eef

Browse files
jroheljan-kolarik
authored andcommitted
PGP: Unit tests: Add tests for binary public key, fix pgp file names
Signature "repod.xml_bad.asc" was in binary format. Therefore, the file extension was changed to ".sig". Files in ASCII Armored format have were renamed to have an ".asc" extension.
1 parent 84c6d3d commit f097eef

7 files changed

Lines changed: 58 additions & 11 deletions

File tree

tests/test_data/repo_yum_01/repodata/generator.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ SUBKEY_KEYID=`gpg -k --with-colons | grep sub | cut -d: -f5`
1616
SUBKEY_FP=`gpg -k --with-colons | grep fpr | tail -n1 | cut -d: -f10`
1717
SUBKEY_CREATION=`gpg -k --with-colons | grep sub | cut -d: -f6`
1818

19-
gpg --batch --passphrase '' --armor --export-secret-key "$USERID" > repomd.xml.key.secret
20-
gpg --batch --armor --export "$USERID" > repomd.xml.key
19+
gpg --batch --passphrase '' --armor --export-secret-key "$USERID" >repomd.xml.private-key.asc
20+
gpg --batch --armor --export "$USERID" >repomd.xml.key.asc
21+
gpg --batch --dearmor <repomd.xml.key.asc >repomd.xml.key
2122
mv repomd.xml.asc repomd.xml.asc~
2223
gpg --batch --armor --sign --detach -o repomd.xml.asc repomd.xml
24+
gpg --batch --dearmor <repomd.xml.asc >repomd.xml.sig
2325

2426
echo "Adjust test_gpg.c with these values:"
2527
echo
-525 Bytes
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-----BEGIN PGP PUBLIC KEY BLOCK-----
2+
3+
mQENBGQCK4MBCACmfps+HeGv3BnrFmOO5PGPFDgQ0KtmSkfkrw8Sf3dcsfiMS9II
4+
2AOJNLd8NOgOkGGlyymrrf/FKPWnQHQDKxLgOuZ0FvAIfb+VNTjnuj8TfO94y7n1
5+
VpCu7oRKOQLfmRd3OQDe0CofNjYeYKn2l/an/x80o3ikoFMEdHcOkdhPkm/Kf5oc
6+
bJYVvxb81v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22+
rIwB+ZoahvjfhC6eg7gh4LNnawARAQABiQE2BBgBCgAgFiEE9PxbasWGlgI7nb+x
23+
l723kGRB7fUFAmQCK4MCGwwACgkQl723kGRB7fV9Dgf9GvTNb36IxIOhyqWFFXZp
24+
C3NqyyIbRZ6KEXUzLaC88fx2hK1BQkeDASUS0HxccCCdjR1zesk0QfZtGJxVQFw+
25+
AyLWzMGRLDfMvXYRLzjYowYJ++beVadt/EfPzRHckunW75PLHrDd89Hur92r4ikK
26+
42GA3ZDPr9yggpnYvsAXt25lDx37HN3SeVds2Gb6wA01Vo6jXVKQGhRgk9K5T8dB
27+
szn12XdPGxhzo1HXPUFWwSi8SODpG+MkC+IGOrFzPHW5R5kOO7+nbALjzLWSrcfw
28+
zLiMgTqA0Z2O8QcTGSQ7jYQhSaWguWzhT1LsZ0/9xNGSHyWfYkYtXPAogB50qlvM
29+
LQ==
30+
=RI7R
31+
-----END PGP PUBLIC KEY BLOCK-----

tests/test_data/repo_yum_01/repodata/repomd.xml.key.secret renamed to tests/test_data/repo_yum_01/repodata/repomd.xml.private-key.asc

File renamed without changes.

tests/test_data/repo_yum_01/repodata/repomd.xml_bad.key renamed to tests/test_data/repo_yum_01/repodata/repomd.xml_bad.key.asc

File renamed without changes.

tests/test_data/repo_yum_01/repodata/repomd.xml_bad.asc renamed to tests/test_data/repo_yum_01/repodata/repomd.xml_bad.sig

File renamed without changes.

tests/test_gpg.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ START_TEST(test_gpg_check_signature)
2626

2727
tmp_home_path = lr_gettmpdir();
2828
key_path = lr_pathconcat(test_globals.testdata_dir,
29-
"repo_yum_01/repodata/repomd.xml.key", NULL);
29+
"repo_yum_01/repodata/repomd.xml.key.asc", NULL);
3030
_key_path = lr_pathconcat(test_globals.testdata_dir,
31-
"repo_yum_01/repodata/repomd.xml_bad.key", NULL);
31+
"repo_yum_01/repodata/repomd.xml_bad.key.asc", NULL);
3232
data_path = lr_pathconcat(test_globals.testdata_dir,
3333
"repo_yum_01/repodata/repomd.xml", NULL);
3434
_data_path = lr_pathconcat(test_globals.testdata_dir,
3535
"repo_yum_01/repodata/repomd.xml_bad", NULL);
3636
signature_path = lr_pathconcat(test_globals.testdata_dir,
3737
"repo_yum_01/repodata/repomd.xml.asc", NULL);
3838
_signature_path = lr_pathconcat(test_globals.testdata_dir,
39-
"repo_yum_01/repodata/repomd.xml_bad.asc", NULL);
39+
"repo_yum_01/repodata/repomd.xml_bad.sig", NULL);
4040

4141
// Import the first key directly from the file
4242
ret = lr_gpg_import_key(key_path, tmp_home_path, &tmp_err);
@@ -124,16 +124,14 @@ START_TEST(test_gpg_check_signature)
124124
}
125125
END_TEST
126126

127-
START_TEST(test_gpg_check_key_export)
127+
128+
static void check_key_import_test_export(const char *key_path)
128129
{
129130
gboolean ret;
130-
char *key_path;
131131
char *tmp_home_path;
132132
GError *tmp_err = NULL;
133133

134134
tmp_home_path = lr_gettmpdir();
135-
key_path = lr_pathconcat(test_globals.testdata_dir,
136-
"repo_yum_01/repodata/repomd.xml.key", NULL);
137135

138136
// Import the key from file descriptor
139137
int key_fd = open(key_path, O_RDONLY);
@@ -227,9 +225,24 @@ START_TEST(test_gpg_check_key_export)
227225

228226
lr_gpg_keys_free(keys);
229227
lr_remove_dir(tmp_home_path);
230-
lr_free(key_path);
231228
g_free(tmp_home_path);
232229
}
230+
231+
232+
START_TEST(test_gpg_check_armored_key_import_test_export)
233+
{
234+
char *key_path = lr_pathconcat(test_globals.testdata_dir, "repo_yum_01/repodata/repomd.xml.key.asc", NULL);
235+
check_key_import_test_export(key_path);
236+
lr_free(key_path);
237+
}
238+
END_TEST
239+
240+
START_TEST(test_gpg_check_binary_key_import_test_export)
241+
{
242+
char *key_path = lr_pathconcat(test_globals.testdata_dir, "repo_yum_01/repodata/repomd.xml.key", NULL);
243+
check_key_import_test_export(key_path);
244+
lr_free(key_path);
245+
}
233246
END_TEST
234247

235248

@@ -239,7 +252,8 @@ gpg_suite(void)
239252
Suite *s = suite_create("gpg");
240253
TCase *tc = tcase_create("Main");
241254
tcase_add_test(tc, test_gpg_check_signature);
242-
tcase_add_test(tc, test_gpg_check_key_export);
255+
tcase_add_test(tc, test_gpg_check_armored_key_import_test_export);
256+
tcase_add_test(tc, test_gpg_check_binary_key_import_test_export);
243257
suite_add_tcase(s, tc);
244258
return s;
245259
}

0 commit comments

Comments
 (0)