]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: extend credentials test to cover encrypted credentials
authorLennart Poettering <lennart@poettering.net>
Thu, 24 Jun 2021 08:28:28 +0000 (10:28 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Jul 2021 07:31:14 +0000 (09:31 +0200)
test/units/testsuite-54.sh

index f8ddff4a30567f437ceeec6ee7805a7560c4d74f..d8c9ffa38be7530d1a5233454407e2ca518fb57d 100755 (executable)
@@ -27,6 +27,30 @@ systemd-run -p LoadCredential=passwd:/etc/passwd \
             rm '${CREDENTIALS_DIRECTORY}/passwd' \
     && { echo 'unexpected success'; exit 1; }
 
+# Now test encrypted credentials (only supported when built with OpenSSL though)
+
+if systemctl --version | grep -q -- +OPENSSL ; then
+    echo -n $RANDOM >/tmp/test-54-plaintext
+    systemd-creds encrypt --name=test-54 /tmp/test-54-plaintext /tmp/test-54-ciphertext
+    systemd-creds decrypt --name=test-54 /tmp/test-54-ciphertext | cmp /tmp/test-54-plaintext
+
+    systemd-run -p LoadCredentialEncrypted=test-54:/tmp/test-54-ciphertext \
+                --wait \
+                --pipe \
+                cat '${CREDENTIALS_DIRECTORY}/test-54' | cmp /tmp/test-54-plaintext
+
+    echo -n $RANDOM >/tmp/test-54-plaintext
+    systemd-creds encrypt --name=test-54 /tmp/test-54-plaintext /tmp/test-54-ciphertext
+    systemd-creds decrypt --name=test-54 /tmp/test-54-ciphertext | cmp /tmp/test-54-plaintext
+
+    systemd-run -p SetCredentialEncrypted=test-54:"`cat /tmp/test-54-ciphertext`" \
+                --wait \
+                --pipe \
+                cat '${CREDENTIALS_DIRECTORY}/test-54' | cmp /tmp/test-54-plaintext
+
+    rm /tmp/test-54-plaintext /tmp/test-54-ciphertext
+fi
+
 systemd-analyze log-level info
 
 echo OK >/testok