@@ -30,11 +30,20 @@ static int tests_passed = 0;
3030} while(0)
3131
3232static const char * test_store_dir = "/tmp/test_pam_llng_secrets" ;
33+ static int machine_id_available = 0 ;
34+
35+ /* Check if /etc/machine-id exists (required for secret store) */
36+ static int check_machine_id (void )
37+ {
38+ struct stat st ;
39+ return stat ("/etc/machine-id" , & st ) == 0 ;
40+ }
3341
3442/* Setup test directory */
3543static void setup (void )
3644{
3745 mkdir (test_store_dir , 0700 );
46+ machine_id_available = check_machine_id ();
3847}
3948
4049/* Recursively remove directory - safe alternative to system("rm -rf") */
@@ -79,6 +88,11 @@ static void cleanup(void)
7988/* Test initialization */
8089static int test_init (void )
8190{
91+ if (!machine_id_available ) {
92+ printf ("SKIP (no machine-id) " );
93+ return 1 ;
94+ }
95+
8296 secret_store_config_t config = {
8397 .enabled = true,
8498 .store_dir = (char * )test_store_dir ,
@@ -97,6 +111,11 @@ static int test_init(void)
97111/* Test store and retrieve */
98112static int test_put_get (void )
99113{
114+ if (!machine_id_available ) {
115+ printf ("SKIP (no machine-id) " );
116+ return 1 ;
117+ }
118+
100119 secret_store_config_t config = {
101120 .enabled = true,
102121 .store_dir = (char * )test_store_dir ,
@@ -131,6 +150,11 @@ static int test_put_get(void)
131150/* Test exists */
132151static int test_exists (void )
133152{
153+ if (!machine_id_available ) {
154+ printf ("SKIP (no machine-id) " );
155+ return 1 ;
156+ }
157+
134158 secret_store_config_t config = {
135159 .enabled = true,
136160 .store_dir = (char * )test_store_dir ,
@@ -156,6 +180,11 @@ static int test_exists(void)
156180/* Test delete */
157181static int test_delete (void )
158182{
183+ if (!machine_id_available ) {
184+ printf ("SKIP (no machine-id) " );
185+ return 1 ;
186+ }
187+
159188 secret_store_config_t config = {
160189 .enabled = true,
161190 .store_dir = (char * )test_store_dir ,
@@ -184,6 +213,11 @@ static int test_delete(void)
184213/* Test not found */
185214static int test_not_found (void )
186215{
216+ if (!machine_id_available ) {
217+ printf ("SKIP (no machine-id) " );
218+ return 1 ;
219+ }
220+
187221 secret_store_config_t config = {
188222 .enabled = true,
189223 .store_dir = (char * )test_store_dir ,
@@ -207,6 +241,11 @@ static int test_not_found(void)
207241/* Test different keys */
208242static int test_different_keys (void )
209243{
244+ if (!machine_id_available ) {
245+ printf ("SKIP (no machine-id) " );
246+ return 1 ;
247+ }
248+
210249 secret_store_config_t config = {
211250 .enabled = true,
212251 .store_dir = (char * )test_store_dir ,
@@ -240,6 +279,11 @@ static int test_different_keys(void)
240279/* Test overwrite */
241280static int test_overwrite (void )
242281{
282+ if (!machine_id_available ) {
283+ printf ("SKIP (no machine-id) " );
284+ return 1 ;
285+ }
286+
243287 secret_store_config_t config = {
244288 .enabled = true,
245289 .store_dir = (char * )test_store_dir ,
@@ -290,6 +334,11 @@ static int test_disabled(void)
290334/* Test binary data */
291335static int test_binary_data (void )
292336{
337+ if (!machine_id_available ) {
338+ printf ("SKIP (no machine-id) " );
339+ return 1 ;
340+ }
341+
293342 secret_store_config_t config = {
294343 .enabled = true,
295344 .store_dir = (char * )test_store_dir ,
@@ -352,6 +401,11 @@ static int test_error_message(void)
352401/* Test rotate key returns error (not implemented) */
353402static int test_rotate_key_not_implemented (void )
354403{
404+ if (!machine_id_available ) {
405+ printf ("SKIP (no machine-id) " );
406+ return 1 ;
407+ }
408+
355409 secret_store_config_t config = {
356410 .enabled = true,
357411 .store_dir = (char * )test_store_dir ,
0 commit comments