Skip to content

Commit

Permalink
chore(build_ssh_test): address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Domenico Salvatore <[email protected]>
  • Loading branch information
banditopazzo committed Oct 14, 2024
1 parent de03e45 commit 008d8ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
33 changes: 30 additions & 3 deletions tests/integration/build_ssh/context/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,35 @@ RUN apk add openssh

# Test the SSH agents during the build

RUN --mount=type=ssh ssh-add -L
RUN --mount=type=ssh \
actual_output="$(ssh-add -L | sed 's/[[:space:]]*$//')" && \
expected_output="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFYQvN9a+toIB6jSs4zY7FMapZnHt80EKCUr/WhLwUum" && \
if [ "$actual_output" != "$expected_output" ]; then \
echo "SSH key mismatch!" && \
echo "$expected_output" > /tmp/expected_key && \
echo "$actual_output" > /tmp/actual_key && \
diff /tmp/expected_key /tmp/actual_key && \
exit 1; \
fi

RUN --mount=type=ssh,id=id1 ssh-add -L
RUN --mount=type=ssh,id=id1 \
actual_output="$(ssh-add -L | sed 's/[[:space:]]*$//')" && \
expected_output="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFYQvN9a+toIB6jSs4zY7FMapZnHt80EKCUr/WhLwUum" && \
if [ "$actual_output" != "$expected_output" ]; then \
echo "SSH key mismatch!" && \
echo "$expected_output" > /tmp/expected_key && \
echo "$actual_output" > /tmp/actual_key && \
diff /tmp/expected_key /tmp/actual_key && \
exit 1; \
fi

RUN --mount=type=ssh,id=id2 ssh-add -L
RUN --mount=type=ssh,id=id2 \
actual_output="$(ssh-add -L | sed 's/[[:space:]]*$//')" && \
expected_output="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFYQvN9a+toIB6jSs4zY7FMapZnHt80EKCUr/WhLwUum" && \
if [ "$actual_output" != "$expected_output" ]; then \
echo "SSH key mismatch!" && \
echo "$expected_output" > /tmp/expected_key && \
echo "$actual_output" > /tmp/actual_key && \
diff /tmp/expected_key /tmp/actual_key && \
exit 1; \
fi
13 changes: 3 additions & 10 deletions tests/integration/build_ssh/test_build_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_build_ssh(self):
finally:
# Now we send the stop command to gracefully shut down the server
agent.stop_agent()
# agent_thread.join()

if os.path.exists(sock_path):
os.remove(sock_path)

Expand Down Expand Up @@ -100,8 +100,8 @@ def _load_ed25519_private_key(self, private_key_path):
+ public_key_blob # Public key length + key blob
)

# Comment (typically username@hostname)
comment = "user@host"
# Comment (empty)
comment = ""

return ("ssh-ed25519", key_blob_full, comment)

Expand All @@ -115,7 +115,6 @@ def start_agent(self, sock_path):
self.server_sock.bind(self.sock_path)
self.server_sock.listen(5)

# print(f"Mock SSH agent running with socket: {self.sock_path}")
os.environ['SSH_AUTH_SOCK'] = self.sock_path

self.running.set() # Set the running event
Expand All @@ -129,7 +128,6 @@ def _accept_connections(self):
while self.running.is_set():
try:
client_sock, _ = self.server_sock.accept()
# print("Connection received, handling client request.")
self._handle_client(client_sock)
except Exception as e:
print(f"Error accepting connection: {e}")
Expand All @@ -148,7 +146,6 @@ def _handle_client(self, client_sock):

# Check for STOP_REQUEST
if request_message[0] == STOP_REQUEST:
# print("Received stop request.")
client_sock.close()
self.running.clear() # Stop accepting connections
return
Expand All @@ -172,8 +169,6 @@ def _handle_client(self, client_sock):
def _mock_list_keys_response(self):
"""Create a mock response for ssh-add -l, listing keys."""

# print("Mocking response")

# Start building the response
response = struct.pack(">B", SSH_AGENT_IDENTITIES_ANSWER) # Message type

Expand Down Expand Up @@ -222,5 +217,3 @@ def stop_agent(self):
if self.server_sock: # Check if the server socket exists
self.server_sock.close() # Close the server socket
os.remove(self.sock_path)

# print("Mock SSH agent stopped.")

0 comments on commit 008d8ef

Please sign in to comment.