<commit_before>#!/bin/bash
# Launch all command line which don't need interactions
# Goal is to be able to test rapidly all the passhport-admin
# basic functions

#GENERAL
PADM="./passhport-admin"

#################
# USER MANAGEMENT
#################
#Variables
CMD="${PADM} user"
USERNAME="<EMAIL>"
COMMENT="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sed neque eget velit ultrices rhoncus nec at tellus. Sed efficitur lobortis erat, at faucibus sapien porttitor porta. Sed cursus, orci et ullamcorper rutrum, libero sapien ornare justo, at pellentesque eros magna sit amet risus. Nam consectetur cursus rutrum. Duis pretium nibh eu est condimentum, vitae ultrices felis suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut tristique posuere tempus. Suspendisse potenti. Curabitur dapibus leo erat, vitae vestibulum risus fermentum id. Donec semper ex augue, non hendrerit neque lacinia a."
SSHKEY="ssh-rsa A<KEY> ${USERNAME}"

#Tests
# Search/show/edit/del on a not existing user
# Creating user
# Creating an already existing user
# Search/show/edit/del an existing user

# SEARCH 1/2
PATTERN="No user matching the pattern \"${USERNAME}\" found."
${CMD} search ${USERNAME} | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] search 1/2: " ${r/1/ERROR}

# SHOW 1/2
PATTERN="ERROR: No user with the name \"${USERNAME}\" in the database."
${CMD} show ${USERNAME} | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] show   1/2: " ${r/1/ERROR}

# EDIT 1/2
PATTERN="ERROR: No user with the name \"${USERNAME}\" in the database."
${CMD} edit ${USERNAME} --newname=new_${USERNAME} --newcomment="${COMMENT}" --newsshkey="${SSHKEY}" | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] edit   1/2: " ${r/1/ERROR}

# DEL 1/2
PATTERN="ERROR: No user with the name \"${USERNAME}\" in the database."
${CMD} delete ${USERNAME} | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] del    1/2: " ${r/1/ERROR}

# CREATE 1/2
PATTERN="OK: \"${USERNAME}\" -> created"
${CMD} create ${USERNAME} "${SSHKEY}" --comment="${COMMENT}" | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] create 1/2: " ${r/1/ERROR}

# CREATE 2/2
PATTERN="ERROR: The name \"${USERNAME}\" is already used by another user"
${CMD} create ${USERNAME} "${SSHKEY}" --comment="${COMMENT}" | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] create 2/2: " ${r/1/ERROR}

# SEARCH 2/2
PATTERN="<EMAIL>"
${CMD} search ${USERNAME} | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] search 2/2: " ${r/1/ERROR}

# SHOW 2/2
PATTERN="Name: ${USERNAME}
SSH key: ${SSHKEY}
Comment: ${COMMENT}"
${CMD} show ${USERNAME} | grep "${PATTERN}" | wc -l | grep 3 &> /dev/null
r=${?/0/OK}
echo "[user] show   2/2: " ${r/1/ERROR}

# EDIT 2/2
PATTERN="OK: \"${USERNAME}\" -> edited"
${CMD} edit ${USERNAME} --newname=new_${USERNAME} --newcomment="${COMMENT}" --newsshkey="${SSHKEY}" | grep "${PATTERN}" &> /dev/null
r=${?/0/OK}
echo "[user] edit   2/2: " ${r/1/ERROR}

# DEL 2/2
PATTERN="OK: \"new_${USERNAME}\" -> deleted"
${CMD} delete new_${USERNAME} | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] del    2/2: " ${r/1/ERROR}<commit_msg>Add -f argument in tests for delete function<commit_after>#!/bin/bash
# Launch all command line which don't need interactions
# Goal is to be able to test rapidly all the passhport-admin
# basic functions

#GENERAL
PADM="./passhport-admin"

#################
# USER MANAGEMENT
#################
#Variables
CMD="${PADM} user"
USERNAME="<EMAIL>"
COMMENT="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sed neque eget velit ultrices rhoncus nec at tellus. Sed efficitur lobortis erat, at faucibus sapien porttitor porta. Sed cursus, orci et ullamcorper rutrum, libero sapien ornare justo, at pellentesque eros magna sit amet risus. Nam consectetur cursus rutrum. Duis pretium nibh eu est condimentum, vitae ultrices felis suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut tristique posuere tempus. Suspendisse potenti. Curabitur dapibus leo erat, vitae vestibulum risus fermentum id. Donec semper ex augue, non hendrerit neque lacinia a."
SSHKEY="<KEY> ${USERNAME}"

#Tests
# Search/show/edit/del on a not existing user
# Creating user
# Creating an already existing user
# Search/show/edit/del an existing user

# SEARCH 1/2
PATTERN="No user matching the pattern \"${USERNAME}\" found."
${CMD} search ${USERNAME} | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] search 1/2: " ${r/1/ERROR}

# SHOW 1/2
PATTERN="ERROR: No user with the name \"${USERNAME}\" in the database."
${CMD} show ${USERNAME} | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] show   1/2: " ${r/1/ERROR}

# EDIT 1/2
PATTERN="ERROR: No user with the name \"${USERNAME}\" in the database."
${CMD} edit ${USERNAME} --newname=new_${USERNAME} --newcomment="${COMMENT}" --newsshkey="${SSHKEY}" | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] edit   1/2: " ${r/1/ERROR}

# DEL 1/2
PATTERN="ERROR: No user with the name \"${USERNAME}\" in the database."
${CMD} delete -f ${USERNAME} | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] del    1/2: " ${r/1/ERROR}

# CREATE 1/2
PATTERN="OK: \"${USERNAME}\" -> created"
${CMD} create ${USERNAME} "${SSHKEY}" --comment="${COMMENT}" | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] create 1/2: " ${r/1/ERROR}

# CREATE 2/2
PATTERN="ERROR: The name \"${USERNAME}\" is already used by another user"
${CMD} create ${USERNAME} "${SSHKEY}" --comment="${COMMENT}" | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] create 2/2: " ${r/1/ERROR}

# SEARCH 2/2
PATTERN="<EMAIL>"
${CMD} search ${USERNAME} | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] search 2/2: " ${r/1/ERROR}

# SHOW 2/2
PATTERN="Name: ${USERNAME}
SSH key: ${SSHKEY}
Comment: ${COMMENT}"
${CMD} show ${USERNAME} | grep "${PATTERN}" | wc -l | grep 3 &> /dev/null
r=${?/0/OK}
echo "[user] show   2/2: " ${r/1/ERROR}

# EDIT 2/2
PATTERN="OK: \"${USERNAME}\" -> edited"
${CMD} edit ${USERNAME} --newname=new_${USERNAME} --newcomment="${COMMENT}" --newsshkey="${SSHKEY}" | grep "${PATTERN}" &> /dev/null
r=${?/0/OK}
echo "[user] edit   2/2: " ${r/1/ERROR}

# DEL 2/2
PATTERN="OK: \"new_${USERNAME}\" -> deleted"
${CMD} delete -f new_${USERNAME} | grep "${PATTERN}"  &> /dev/null
r=${?/0/OK}
echo "[user] del    2/2: " ${r/1/ERROR}
{'fraction_non_alphanumeric': 0.2059282371294852, 'fraction_numerical': 0.01903276131045242, 'mean_word_length': 4.329177057356609, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1209696', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2434, 'n_words': 733}