Skip to content

Add solution for Challenge 5 by Raycas96#1565

Merged
github-actions[bot] merged 2 commits intoRezaSi:mainfrom
Raycas96:challenge-5-Raycas96
Apr 13, 2026
Merged

Add solution for Challenge 5 by Raycas96#1565
github-actions[bot] merged 2 commits intoRezaSi:mainfrom
Raycas96:challenge-5-Raycas96

Conversation

@Raycas96
Copy link
Copy Markdown
Contributor

@Raycas96 Raycas96 commented Apr 8, 2026

Challenge 5 Solution

Submitted by: @Raycas96
Challenge: Challenge 5

Description

This PR contains my solution for Challenge 5.

Changes

  • Added solution file to challenge-5/submissions/Raycas96/solution-template.go

Testing

  • Solution passes all test cases
  • Code follows Go best practices

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 8, 2026

Walkthrough

A Go HTTP server implementation has been added with authentication middleware and two endpoint handlers. The AuthMiddleware validates requests via the X-Auth-Token header against a hardcoded "secret" token. The /hello endpoint is publicly accessible, while /secure requires authentication. The SetupServer function wires the routes.

Changes

Cohort / File(s) Summary
HTTP Server with Authentication
challenge-5/submissions/Raycas96/solution-template.go
Added AuthMiddleware that validates X-Auth-Token header, two HTTP handlers (helloHandler and secureHandler), SetupServer to register routes with middleware, and a validToken constant ("secret").

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant Server as HTTP Server
    participant AuthMW as AuthMiddleware
    participant SecureHandler as secureHandler

    rect rgba(0, 150, 0, 0.5)
    Note over Client,SecureHandler: Request with Valid Token
    Client->>Server: GET /secure<br/>X-Auth-Token: secret
    Server->>AuthMW: Check authentication
    AuthMW->>AuthMW: Validate token matches "secret"
    AuthMW->>SecureHandler: Token valid, forward request
    SecureHandler->>Client: 200 OK<br/>"You are authorized!"
    end

    rect rgba(150, 0, 0, 0.5)
    Note over Client,SecureHandler: Request without Token
    Client->>Server: GET /secure<br/>(no X-Auth-Token header)
    Server->>AuthMW: Check authentication
    AuthMW->>AuthMW: Token header missing
    AuthMW->>Client: 401 Unauthorized
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 A secret token guards the way,
AuthMiddleware checks each day,
/secure paths are now protected tight,
While /hello greets with pure delight!
Hoppy authentication hops just right! 🔐

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: submitting a solution for Challenge 5, which matches the added solution file in the changeset.
Description check ✅ Passed The description is relevant to the changeset, explaining it's a Challenge 5 solution submission with clear details about the file added and testing status.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (1)
challenge-5/submissions/Raycas96/solution-template.go (1)

18-18: Use validToken in the auth check and simplify the condition.

At Line [18], authHeader == "" || authHeader != "secret" is redundant and hardcodes the token literal again. Prefer a single comparison against validToken.

Proposed cleanup
-		if authHeader == "" || authHeader != "secret"  {
+		if authHeader != validToken {
 		    http.Error(w, "", http.StatusUnauthorized)
 		    return 
 		}

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d033ea28-ecca-4f0a-94ec-3830bd562571

📥 Commits

Reviewing files that changed from the base of the PR and between 6a002af and 4fd484c.

📒 Files selected for processing (1)
  • challenge-5/submissions/Raycas96/solution-template.go

fmt.Fprint(w, "Hello!")
}

// secureHandler returns "You are authorized!" on GET /secure
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Update the handler comment to avoid implying GET-only behavior.

Line [32] says “on GET /secure”, but this handler is correctly method-agnostic. Keeping the comment as-is can mislead future edits into adding method restrictions that would break expected behavior.

Based on learnings: In challenge-5/submissions/*/solution-template.go, ensure the secureHandler is method-agnostic (do not restrict it to GET), and tests include POST /secure with valid token expecting 200 OK.

@github-actions github-actions Bot merged commit 2712368 into RezaSi:main Apr 13, 2026
6 checks passed
@github-actions
Copy link
Copy Markdown

🎉 Auto-merged!

This PR was automatically merged after 2 days with all checks passing.

Thank you for your contribution, @Raycas96!

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.

2 participants