t_netpgpkeys.sh revision 1.3
1#! /bin/sh
2
3# $NetBSD: t_netpgpkeys.sh,v 1.3 2026/01/31 22:35:10 wiz Exp $
4
5#
6# Copyright (c) 2026 The NetBSD Foundation, Inc.
7# All rights reserved.
8#
9# This code is derived from software contributed to The NetBSD Foundation
10# by Thomas Klausner <wiz@NetBSD.org>
11#
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions
14# are met:
15# 1. Redistributions of source code must retain the above copyright
16#    notice, this list of conditions and the following disclaimer.
17# 2. Redistributions in binary form must reproduce the above copyright
18#    notice, this list of conditions and the following disclaimer in the
19#    documentation and/or other materials provided with the distribution.
20#
21# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22# AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31# POSSIBILITY OF SUCH DAMAGE.
32#
33
34cleanup_core() {
35	local prog
36
37	prog=$1
38	test -f "${prog}.core" || return 0
39	readelf -rs "/usr/bin/${prog}"
40	gdb -batch -ex bt -ex 'info registers' -ex disas \
41	    "/usr/bin/${prog}" "${prog}.core"
42}
43
44# Test set 1 (rsa key) for netpgpkeys
45atf_test_case netpgpkeys_testset_1_rsa_keys
46
47netpgpkeys_testset_1_rsa_keys_head() {
48	atf_set "descr" "Test set 1 (rsa_keys) for netpgpkeys"
49}
50netpgpkeys_testset_1_rsa_keys_body() {
51	atf_expect_fail "PR bin/59936 - does not support keys generated by gnugp2"
52	# TODO: fix netpgpkeys so it doesn't need an empty keyring
53	atf_check touch pubring.gpg
54	atf_check netpgpkeys --keyring pubring.gpg \
55		  --import-key "$(atf_get_srcdir)"/data/testkey-rsa.pub
56}
57
58# Test set 2 (elliptic curve keys) for netpgpkeys
59atf_test_case netpgpkeys_testset_2_ec_keys cleanup
60
61netpgpkeys_testset_2_ec_keys_head() {
62	atf_set "descr" "Test set 2 (ec_keys) for netpgpkeys"
63}
64netpgpkeys_testset_2_ec_keys_body() {
65	atf_expect_fail "PR bin/59936 - does not support keys generated by gnugp2 - dumps core for EC keys"
66	# TODO: fix netpgpkeys so it doesn't need an empty keyring
67	atf_check touch pubring.gpg
68	atf_check netpgpkeys --keyring pubring.gpg \
69		  --import-key "$(atf_get_srcdir)"/data/testkey-ec.pub \
70		  --coredumps
71}
72
73netpgpkeys_testset_2_ec_keys_cleanup() {
74	cleanup_core netpgpkeys
75}
76
77# all test sets
78atf_init_test_cases() {
79	atf_add_test_case netpgpkeys_testset_1_rsa_keys
80	atf_add_test_case netpgpkeys_testset_2_ec_keys
81}
82