Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test script #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add test script #33

wants to merge 3 commits into from

Conversation

PeterDaveHello
Copy link
Owner

@PeterDaveHello PeterDaveHello commented Jan 12, 2025

💪

Summary by CodeRabbit

  • New Features

    • Added a comprehensive test script for domain validation testing.
    • Implemented parallel testing for valid and invalid domain checks.
  • Chores

    • Updated CI configuration to use the new test script.
    • Improved test execution and reporting process.

@PeterDaveHello PeterDaveHello self-assigned this Jan 12, 2025
Copy link
Contributor

coderabbitai bot commented Jan 12, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a new Bash script test_chkdm.sh to replace direct calls to the chkdm script in the Travis CI configuration. The .travis.yml file has been updated to use this new script for testing domain validation. The new script provides a structured approach to testing valid and invalid domain names, with enhanced reporting and parallel test execution capabilities.

Changes

File Change Summary
.travis.yml Replaced direct chkdm script calls with ./test_chkdm.sh in Ubuntu and macOS test stages
test_chkdm.sh New script added with functions for testing domain validation, including:
- get_time_ms
- format_duration
- test_single_valid_domain
- test_valid_domains
- test_invalid_domains
- check_chkdm_executable
- main orchestration function

Sequence Diagram

sequenceDiagram
    participant CI as Travis CI
    participant TestScript as test_chkdm.sh
    participant Chkdm as chkdm executable
    
    CI->>TestScript: Execute test script
    TestScript->>TestScript: Check chkdm executable
    TestScript->>Chkdm: Test valid domains
    Chkdm-->>TestScript: Validation results
    TestScript->>Chkdm: Test invalid domains
    Chkdm-->>TestScript: Validation results
    TestScript-->>CI: Report test summary
Loading

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • test_chkdm.sh: Language not supported
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
test_chkdm.sh (3)

50-53: Improve temporary directory cleanup.

The cleanup trap could fail if the script is interrupted during directory creation. Move the trap before directory creation:

-    local tmp_dir
-    tmp_dir=$(mktemp -d)
-    trap 'rm -rf "$tmp_dir"' EXIT
+    local tmp_dir
+    trap 'rm -rf "${tmp_dir:-}"' EXIT
+    tmp_dir=$(mktemp -d)

81-126: Consider parallelizing invalid domain tests.

The invalid domain tests are run sequentially. Consider using the same parallel execution strategy as test_valid_domains for consistent performance:

 test_invalid_domains() {
     # ... existing setup ...

+    local tmp_dir
+    trap 'rm -rf "${tmp_dir:-}"' EXIT
+    tmp_dir=$(mktemp -d)
+
     for domain in "${invalid_domains[@]}"; do
         echo -e "  Testing domain: ${BLUE}$domain${NC}"
-        local test_start_time test_end_time test_duration
-        test_start_time=$(date +%s%N)
-
-        if $CHKDM "$domain" > /dev/null 2>&1; then
-            echo -e "    ${RED}✗ Error: domain '$domain' was marked as valid${NC}"
-        else
-            echo -e "    ${GREEN}✓ OK${NC}"
-            ((passed++))
-        fi
-
-        test_end_time=$(date +%s%N)
-        test_duration=$(( (test_end_time - test_start_time) / 1000000 ))
-        echo -e "    ${BLUE}Time: ${YELLOW}${test_duration}ms${NC}\n"
+        (
+            local test_start_time test_end_time test_duration
+            test_start_time=$(date +%s%N)
+
+            if $CHKDM "$domain" > /dev/null 2>&1; then
+                echo -e "    ${RED}✗ Error: domain '$domain' was marked as valid${NC}"
+                echo "0" > "$tmp_dir/$domain"
+            else
+                echo -e "    ${GREEN}✓ OK${NC}"
+                echo "1" > "$tmp_dir/$domain"
+            fi
+
+            test_end_time=$(date +%s%N)
+            test_duration=$(( (test_end_time - test_start_time) / 1000000 ))
+            echo -e "    ${BLUE}Time: ${YELLOW}${test_duration}ms${NC}\n"
+        ) &
     done

+    wait
+
+    for domain in "${invalid_domains[@]}"; do
+        if [ -f "$tmp_dir/$domain" ] && [ "$(cat "$tmp_dir/$domain")" = "1" ]; then
+            ((passed++))
+        fi
+    done

128-143: Enhance executable check with version information.

Add version information to the executable check for better debugging:

 check_chkdm_executable() {
     echo -e "  ${BLUE}Checking program: ${NC}"
     if [ ! -f "$CHKDM" ]; then
         echo -e "    ${RED}✗ Error: program not found${NC}"
         return 1
     fi
     echo -e "    ${GREEN}✓ Found${NC}"

     echo -e "  ${BLUE}Checking permissions${NC}"
     if [ ! -x "$CHKDM" ]; then
         echo -e "    ${RED}✗ Error: program is not executable${NC}"
         return 1
     fi
     echo -e "    ${GREEN}✓ Executable${NC}\n"
+
+    echo -e "  ${BLUE}Version information:${NC}"
+    if ! $CHKDM --version; then
+        echo -e "    ${YELLOW}! Warning: Could not get version information${NC}\n"
+    fi
+
     return 0
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 59e1985 and f10cd89.

📒 Files selected for processing (2)
  • .travis.yml (2 hunks)
  • test_chkdm.sh (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Travis CI - Pull Request
  • GitHub Check: Travis CI - Branch
🔇 Additional comments (2)
.travis.yml (1)

35-38: LGTM! Test scenarios are well-preserved.

The changes effectively centralize test execution in test_chkdm.sh while maintaining coverage of all scenarios:

  • Default configuration
  • Custom DNS file
  • Missing default DNS file
  • Non-existent custom DNS file

Also applies to: 67-70

test_chkdm.sh (1)

145-187: LGTM! Well-structured main function.

The main function effectively:

  • Orchestrates test execution
  • Handles errors appropriately
  • Provides clear test summary and timing information

test_chkdm.sh Outdated
Comment on lines 12 to 49
test_single_valid_domain() {
local domain="$1"
local start_time end_time duration
start_time=$(date +%s%N)
local result=0

if ! $CHKDM "$domain" > /dev/null 2>&1; then
echo -e " ${RED}✗ Error: domain '$domain' was marked as invalid${NC}"
result=1
else
echo -e " ${GREEN}✓ OK${NC}"
fi

end_time=$(date +%s%N)
duration=$(( (end_time - start_time) / 1000000 ))
echo -e " ${BLUE}Time: ${YELLOW}${duration}ms${NC}\n"

return $result
}
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add timeout handling to prevent hanging tests.

Add a timeout to test_single_valid_domain to prevent hanging on slow DNS responses:

 test_single_valid_domain() {
     local domain="$1"
     local start_time end_time duration
     start_time=$(date +%s%N)
     local result=0

-    if ! $CHKDM "$domain" > /dev/null 2>&1; then
+    if ! timeout 10s $CHKDM "$domain" > /dev/null 2>&1; then
         echo -e "    ${RED}✗ Error: domain '$domain' was marked as invalid${NC}"
         result=1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test_single_valid_domain() {
local domain="$1"
local start_time end_time duration
start_time=$(date +%s%N)
local result=0
if ! $CHKDM "$domain" > /dev/null 2>&1; then
echo -e " ${RED}✗ Error: domain '$domain' was marked as invalid${NC}"
result=1
else
echo -e " ${GREEN}✓ OK${NC}"
fi
end_time=$(date +%s%N)
duration=$(( (end_time - start_time) / 1000000 ))
echo -e " ${BLUE}Time: ${YELLOW}${duration}ms${NC}\n"
return $result
}
test_single_valid_domain() {
local domain="$1"
local start_time end_time duration
start_time=$(date +%s%N)
local result=0
if ! timeout 10s $CHKDM "$domain" > /dev/null 2>&1; then
echo -e " ${RED}✗ Error: domain '$domain' was marked as invalid${NC}"
result=1
else
echo -e " ${GREEN}✓ OK${NC}"
fi
end_time=$(date +%s%N)
duration=$(( (end_time - start_time) / 1000000 ))
echo -e " ${BLUE}Time: ${YELLOW}${duration}ms${NC}\n"
return $result
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but a timeout result won't match the corresponding error message, does it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PeterDaveHello You're absolutely right - a timeout would produce a different exit code (124) compared to a domain validation failure. We should handle it separately. Here's an improved version:

test_single_valid_domain() {
    local domain="$1"
    local start_time end_time duration
    start_time=$(date +%s%N)
    local result=0

    if ! timeout 10s $CHKDM "$domain" > /dev/null 2>&1; then
        if [ $? -eq 124 ]; then
            echo -e "    ${RED}✗ Error: domain '$domain' check timed out after 10s${NC}"
        else
            echo -e "    ${RED}✗ Error: domain '$domain' was marked as invalid${NC}"
        fi
        result=1
    else
        echo -e "    ${GREEN}✓ OK${NC}"
    fi

    end_time=$(date +%s%N)
    duration=$(( (end_time - start_time) / 1000000 ))
    echo -e "    ${BLUE}Time: ${YELLOW}${duration}ms${NC}\n"

    return $result
}

This version distinguishes between timeout errors and validation failures. Would you prefer this approach, or would you rather not have timeout handling at all?

(_/)

(・ω・)

⊂ノ

Comment on lines +1 to +10
#!/usr/bin/env bash

SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
CHKDM="${SCRIPT_DIR}/chkdm"

RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
NC='\033[0m'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add script safety flags and improve portability.

  1. Add safety flags to catch errors early:
 #!/usr/bin/env bash
+set -euo pipefail
+IFS=$'\n\t'
  1. Make readlink usage portable to macOS:
-SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/usr/bin/env bash
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
CHKDM="${SCRIPT_DIR}/chkdm"
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
NC='\033[0m'
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CHKDM="${SCRIPT_DIR}/chkdm"
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
NC='\033[0m'

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (2)
test_chkdm.sh (2)

1-4: ⚠️ Potential issue

Add script safety flags and improve portability.

Previous feedback about script safety and portability remains unaddressed.

Apply these changes:

 #!/usr/bin/env bash
+set -euo pipefail
+IFS=$'\n\t'
 
-SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

31-49: ⚠️ Potential issue

Add timeout handling and input validation.

  1. Previous feedback about timeout handling remains unaddressed.
  2. Missing input validation for the domain parameter.
 test_single_valid_domain() {
     local domain="$1"
+    [[ -z "$domain" ]] && { echo "Domain parameter is required"; return 1; }
+
     local start_time end_time duration
     start_time=$(get_time_ms)
     local result=0

-    if ! $CHKDM "$domain" > /dev/null 2>&1; then
+    if ! timeout 10s $CHKDM "$domain" > /dev/null 2>&1; then
         echo -e "    ${RED}✗ Error: domain '$domain' was marked as invalid${NC}"
         result=1
🧹 Nitpick comments (5)
test_chkdm.sh (5)

6-10: Declare color variables as readonly constants.

Color codes should be declared as readonly to prevent accidental modification.

-RED='\033[0;31m'
-GREEN='\033[0;32m'
-BLUE='\033[0;34m'
-YELLOW='\033[0;33m'
-NC='\033[0m'
+readonly RED='\033[0;31m'
+readonly GREEN='\033[0;32m'
+readonly BLUE='\033[0;34m'
+readonly YELLOW='\033[0;33m'
+readonly NC='\033[0m'

22-29: Improve duration formatting precision.

The current implementation loses precision by only showing "<1" for durations less than 1ms.

 format_duration() {
     local duration=$1
     if (( duration < 1000000 )); then
-        echo "<1"
+        printf "%.2f" "$(echo "scale=2; $duration/1000000" | bc)"
     else
-        echo "$((duration / 1000000))"
+        printf "%.0f" "$(echo "scale=0; $duration/1000000" | bc)"
     fi
 }

101-112: Enhance invalid domain test cases.

Consider adding more edge cases:

  • Domains with leading/trailing hyphens
  • Punycode domains
  • Mixed case domains
     local invalid_domains=(
         "example.123"
         "example.c-m"
         "example.a"
         "this-is-a-very-long-label-that-exceeds-the-63-character-limit123.com"
         "sub.this-is-another-very-long-label-that-exceeds-the-63-character-limit.net"
         "example--domain.com"
         "sub--domain.net"
         ""
         "test..domain"
         "invalid#domain.com"
+        "-leading-hyphen.com"
+        "trailing-hyphen-.com"
+        "xn--invalid-punycode"
+        "MIXED.case.DOMAIN"
     )

164-204: Add command-line options for better usability.

Consider adding options for:

  • Verbose mode
  • Running specific test suites
  • Custom timeout values

Example implementation:

parse_args() {
    while getopts "vt:h" opt; do
        case $opt in
            v) VERBOSE=1 ;;
            t) TIMEOUT="$OPTARG" ;;
            h) show_help; exit 0 ;;
            *) show_help; exit 1 ;;
        esac
    done
}

1-206: Overall assessment: Good foundation with room for improvement.

The script provides a solid testing framework with:
✓ Well-structured test organization
✓ Clear output formatting
✓ Good error handling

Key areas for improvement:

  1. Address previous review comments about script safety and timeout handling
  2. Enhance security with proper path validation
  3. Add more configuration options for better usability
  4. Improve robustness of temporary file operations

Consider splitting the script into modules for better maintainability:

  • Move test cases to separate configuration files
  • Create a library file for common functions
  • Implement a plugin system for custom domain validators
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f10cd89 and 8f36c6f.

📒 Files selected for processing (2)
  • .travis.yml (2 hunks)
  • test_chkdm.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .travis.yml
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Travis CI - Pull Request
  • GitHub Check: Travis CI - Branch

Comment on lines +69 to +71
local tmp_dir
tmp_dir=$(mktemp -d)
trap 'rm -rf "$tmp_dir"' EXIT
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for temporary directory operations.

The script should handle failures in temporary directory creation and ensure atomic file operations.

-    tmp_dir=$(mktemp -d)
+    tmp_dir=$(mktemp -d) || { echo "Failed to create temp directory"; return 1; }
+    chmod 700 "$tmp_dir"
     trap 'rm -rf "$tmp_dir"' EXIT
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
local tmp_dir
tmp_dir=$(mktemp -d)
trap 'rm -rf "$tmp_dir"' EXIT
local tmp_dir
tmp_dir=$(mktemp -d) || { echo "Failed to create temp directory"; return 1; }
chmod 700 "$tmp_dir"
trap 'rm -rf "$tmp_dir"' EXIT

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which part ensures the atomic file operations, chmod 700?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PeterDaveHello You're right to question this. I apologize for the confusion in my previous comment. The chmod 700 command only sets directory permissions (read/write/execute for the owner only) and doesn't ensure atomic operations. The mktemp -d command does provide safety by atomically creating a unique temporary directory, but I was incorrect to mention "atomic file operations" in the context of these changes. Would you like me to revise my suggestion to focus solely on error handling for temporary directory creation?


✏️ Learnings added
Learnt from: PeterDaveHello
PR: PeterDaveHello/chkdomain#33
File: test_chkdm.sh:69-71
Timestamp: 2025-01-14T16:42:09.715Z
Learning: The suggestion to ensure "atomic file operations" was incorrect in the context of temporary directory creation. The `chmod 700` command only sets directory permissions (rwx for owner only) and doesn't provide atomicity. The `mktemp -d` command itself provides safety by atomically creating a unique temporary directory.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment on lines +147 to +162
check_chkdm_executable() {
echo -e " ${BLUE}Checking program: ${NC}"
if [ ! -f "$CHKDM" ]; then
echo -e " ${RED}✗ Error: program not found${NC}"
return 1
fi
echo -e " ${GREEN}✓ Found${NC}"

echo -e " ${BLUE}Checking permissions${NC}"
if [ ! -x "$CHKDM" ]; then
echo -e " ${RED}✗ Error: program is not executable${NC}"
return 1
fi
echo -e " ${GREEN}✓ Executable${NC}\n"
return 0
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add absolute path validation.

Ensure the CHKDM path is absolute to prevent potential security issues.

 check_chkdm_executable() {
+    if [[ "$CHKDM" != /* ]]; then
+        echo -e "    ${RED}✗ Error: program path must be absolute${NC}"
+        return 1
+    fi
+
     echo -e "  ${BLUE}Checking program: ${NC}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
check_chkdm_executable() {
echo -e " ${BLUE}Checking program: ${NC}"
if [ ! -f "$CHKDM" ]; then
echo -e " ${RED}✗ Error: program not found${NC}"
return 1
fi
echo -e " ${GREEN}✓ Found${NC}"
echo -e " ${BLUE}Checking permissions${NC}"
if [ ! -x "$CHKDM" ]; then
echo -e " ${RED}✗ Error: program is not executable${NC}"
return 1
fi
echo -e " ${GREEN}✓ Executable${NC}\n"
return 0
}
check_chkdm_executable() {
if [[ "$CHKDM" != /* ]]; then
echo -e " ${RED}✗ Error: program path must be absolute${NC}"
return 1
fi
echo -e " ${BLUE}Checking program: ${NC}"
if [ ! -f "$CHKDM" ]; then
echo -e " ${RED}✗ Error: program not found${NC}"
return 1
fi
echo -e " ${GREEN}✓ Found${NC}"
echo -e " ${BLUE}Checking permissions${NC}"
if [ ! -x "$CHKDM" ]; then
echo -e " ${RED}✗ Error: program is not executable${NC}"
return 1
fi
echo -e " ${GREEN}✓ Executable${NC}\n"
return 0
}

@PeterDaveHello
Copy link
Owner Author

/review

Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 Security concerns

Command Injection:
The script uses variables in command execution (e.g., $CHKDM) without proper quoting in some places. While the risk is low since inputs are controlled, it's best practice to always quote variables in bash scripts to prevent command injection vulnerabilities.

⚡ Recommended focus areas for review

Race Condition

The parallel test execution for valid domains uses temporary files to track results. While there is a trap to cleanup files, concurrent writes to the same file could potentially cause race conditions.

for domain in "${valid_domains[@]}"; do
    echo -e "  Testing domain: ${BLUE}$domain${NC}"
    (
        if test_single_valid_domain "$domain"; then
            echo "1" > "$tmp_dir/$domain"
        else
            echo "0" > "$tmp_dir/$domain"
        fi
    ) &
done

wait
Error Handling

The script does not properly handle edge cases where get_time_ms fails or returns invalid values, which could cause incorrect duration calculations or script failures.

get_time_ms() {
    if command -v gdate >/dev/null 2>&1; then
        gdate +%s%N
    elif date --version >/dev/null 2>&1 && date +%N >/dev/null 2>&1; then
        date +%s%N
    else
        echo $(($(date +%s) * 1000000000))
    fi
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant