Skip to content

Commit

Permalink
Case insensitive username comparison (#421)
Browse files Browse the repository at this point in the history
* Ensure user names are handled as lower case

signer names (GitHub usernames) are compared in quite a few places:
Ensure that comparisons are case-insensitive by always processing
lowercase names

* When reading in signer configuration from .tuf-on-ci-sign.ini,
  convert to lower case
* When taking in signer names as input when modifying a delegation,
  convert to lower case

* tests: Test case insensitive user names

Use a capital letter in both the config file and in tuf-on-ci-delegate
input.

Most of the changes are just ensuring the filepaths of test results
stay the same.
  • Loading branch information
jku authored Sep 9, 2024
1 parent 64950f9 commit 36dea05
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion signer/tuf_on_ci_sign/_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, path: str):
if not self._config:
raise click.ClickException(f"Settings file {path} not found")
try:
self.name = self._config["settings"]["user-name"]
self.name = self._config["settings"]["user-name"].lower()
if not self.name.startswith("@"):
self.name = f"@{self.name}"
self.push_remote = self._config["settings"]["push-remote"]
Expand Down
2 changes: 1 addition & 1 deletion signer/tuf_on_ci_sign/delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def verify_signers(response: str) -> list[str]:

signers: list[str] = []
for s in response.split(","):
s = s.strip()
s = s.strip().lower()
if not s.startswith("@"):
s = f"@{s}"

Expand Down
32 changes: 16 additions & 16 deletions tests/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ repo_setup()
signer_setup()
{
USER=$1
SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"

mkdir -p $SIGNER_GIT

# initialize softhsm: Make it look like we have HW key attached
echo "directories.tokendir = $SIGNER_DIR/tokens" > "$SIGNER_DIR/softhsm2.conf"
cp -r $SCRIPT_DIR/softhsm/tokens-$USER $SIGNER_DIR/tokens
cp -r "$SCRIPT_DIR/softhsm/tokens-${USER,,}" $SIGNER_DIR/tokens

# clone the test repository
git_clone $SIGNER_GIT $UPSTREAM_GIT "$USER@example.com" "$USER"
Expand All @@ -123,7 +123,7 @@ signer_init()
USER=$1
EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand Down Expand Up @@ -153,7 +153,7 @@ signer_add_delegation()
USER1=$1
EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER1"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER1,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand Down Expand Up @@ -184,7 +184,7 @@ signer_change_root_signer()
USER2=$2
EVENT=$3

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER1"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER1,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand All @@ -211,7 +211,7 @@ signer_init_shorter_snapshot_expiry()
USER=$1
EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand Down Expand Up @@ -244,7 +244,7 @@ signer_init_offline_roles_in_signing_period()
USER=$1
EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand Down Expand Up @@ -280,15 +280,15 @@ signer_init_multiuser()
USER=$1
EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

INPUT=(
"" # Configure root? [enter to continue]
"1" # Configure targets? [1: configure signers]
"1" # Chose offline signer
"@tuf-on-ci-user1, @tuf-on-ci-user2" # Enter signers
"@tuf-on-ci-user1, @tuf-on-ci-User2" # Enter signers
"2" # Enter threshold
"" # Configure targets? [enter to continue]
"1" # Configure online roles? [1: configure key]
Expand All @@ -313,7 +313,7 @@ signer_accept_invite()
USER=$1
EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand All @@ -339,7 +339,7 @@ signer_sign()

EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand All @@ -360,7 +360,7 @@ signer_add_targets()
USER=$1
EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand All @@ -382,7 +382,7 @@ signer_modify_targets()
USER=$1
EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand All @@ -403,7 +403,7 @@ signer_add_delegated_targets()
USER=$1
EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand All @@ -427,7 +427,7 @@ non_signer_change_online_delegation()
USER=$1
EVENT=$2

SIGNER_DIR="$WORK_DIR/$TEST_NAME/$USER"
SIGNER_DIR="$WORK_DIR/$TEST_NAME/${USER,,}"
SIGNER_GIT="$SIGNER_DIR/git"
export SOFTHSM2_CONF="$SIGNER_DIR/softhsm2.conf"

Expand Down Expand Up @@ -551,7 +551,7 @@ setup_test() {
mkdir -p $REPO_GIT $UPSTREAM_GIT $PUBLISH_DIR

repo_setup
signer_setup "user1"
signer_setup "User1"
signer_setup "user2"
}

Expand Down

0 comments on commit 36dea05

Please sign in to comment.