toolkit/func/stacks/ipa/20-ipa-user.sh

82 lines
1.9 KiB
Bash
Raw Permalink Normal View History

2021-07-05 06:50:25 +00:00
#!/bin/bash
if m_getArch aarch64 | grep -qE 'aarch64'; then
r_log "ipa $0" "Skipping for aarch64"
exit 0
fi
2022-06-20 23:49:14 +00:00
if [ "$IPAINSTALLED" -eq 1 ]; then
2021-07-05 06:50:25 +00:00
r_log "ipa" "IPA was not successfully installed. Aborting."
r_checkExitStatus 1
fi
2022-06-20 23:49:14 +00:00
kdestroy &> /dev/null
klist 2>&1 | grep -E "(No credentials|Credentials cache .* not found)" &> /dev/null
r_checkExitStatus $?
2022-06-30 03:45:58 +00:00
echo "b1U3OnyX!" | kinit admin@RLIPA.LOCAL
2022-06-20 23:49:14 +00:00
klist | grep "admin@RLIPA.LOCAL" &> /dev/null
r_checkExitStatus $?
r_log "ipa" "Test adding a user"
2022-06-30 04:27:50 +00:00
ipa user-add --first=test --last=user --random ipatestuser > /tmp/ipatestuser
grep -q 'Added user "ipatestuser"' /tmp/ipatestuser
ret_val=$?
if [ "$ret_val" -ne 0 ]; then
r_log "ipa" "User was not created, this is considered fatal"
r_checkExitStatus 1
exit 1
fi
2022-06-20 23:49:14 +00:00
2022-06-30 04:27:50 +00:00
sed -i 's|^ ||g' /tmp/ipatestuser
grep -q 'First name: test' /tmp/ipatestuser
2022-06-20 23:49:14 +00:00
r_checkExitStatus $?
2022-06-30 04:27:50 +00:00
grep -q 'Last name: user' /tmp/ipatestuser
2022-06-20 23:49:14 +00:00
r_checkExitStatus $?
2022-06-30 04:27:50 +00:00
grep -q 'Full name: test user' /tmp/ipatestuser
2022-06-20 23:49:14 +00:00
r_checkExitStatus $?
2022-06-30 04:27:50 +00:00
grep -q 'Home directory: /home/ipatestuser' /tmp/ipatestuser
2022-06-20 23:49:14 +00:00
r_checkExitStatus $?
r_log "ipa" "Changing password of the user"
kdestroy &> /dev/null
2022-06-30 04:27:50 +00:00
userPassword="$(awk '/Random password/ { print $3 }' /tmp/ipatestuser)"
/bin/rm /tmp/ipatestuser
2022-06-20 23:49:14 +00:00
expect -f - <<EOF
set send_human {.1 .3 1 .05 2}
spawn kinit ipatestuser
sleep 1
expect "Password for ipatestuser@RLIPA.LOCAL: "
2022-06-30 04:27:50 +00:00
send -h -- "$(echo "$userPassword")\r"
2022-06-20 23:49:14 +00:00
sleep 1
expect "Enter new password: "
send -h -- "gr@YAm3thy5st!\r"
sleep 1
expect "Enter it again: "
send -h -- "gr@YAm3thy5st!\r"
sleep 5
close
EOF
r_log "ipa" "Re-doing a kinit"
expect -f - <<EOF
set send_human {.1 .3 1 .05 2}
spawn kinit ipatestuser
sleep 1
expect "Password for ipatestuser@C6IPA.LOCAL:"
send -h "gr@YAm3thy5st!\r"
sleep 1
close
EOF
klist | grep "ipatestuser@RLIPA.LOCAL" &> /dev/null
r_checkExitStatus $?
kdestroy &> /dev/null
r_log "ipa" "Testing for user in getent"
getent passwd ipatestuser &> /dev/null
r_checkExitStatus $?