8000 Feat fix 308 redirect by vermakhushboo · Pull Request #9553 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feat fix 308 redirect #9553

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

Merged
merged 6 commits into from
Mar 27, 2025
Merged

Feat fix 308 redirect #9553

merged 6 commits into from
Mar 27, 2025

Conversation

vermakhushboo
Copy link
Member
@vermakhushboo vermakhushboo commented Mar 21, 2025

What does this PR do?

Test for 308 redirect

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

Summary by CodeRabbit

  • Tests
    • Introduced automated tests to verify that permanent redirects are handled correctly by confirming successful page responses.
    • Added dedicated test pages in sub-directory structures to support validation of site navigation and content delivery.

@vermakhushboo vermakhushboo requested a review from Meldiron March 21, 2025 12:25
Copy link
coderabbitai bot commented Mar 21, 2025

Walkthrough

This change introduces a new end-to-end test method testPermanentRedirect in the SitesCustomServerTest class. The test sets up a site, deploys it with a given code package, and validates HTTP responses for both the root path and a specific project path with a trailing slash. Additionally, two new HTML files have been added to serve as content for subdirectories in the test resources.

Changes

File(s) Change Summary
tests/e2e/.../SitesCustomServerTest.php Added new public method testPermanentRedirect that initializes a site, configures a domain, creates a deployment, and uses a proxy client to verify HTTP 200 responses at both the root and specific project path.
tests/resources/sites/sub-directories/index.html
tests/resources/sites/sub-directories/project1/index.html
Introduced two new HTML files containing basic HTML structure. The first displays "Sub-directory index" and the second displays "Sub-directory project1".

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Runner
    participant S as SitesCustomServerTest
    participant Site as Site Engine
    participant Proxy as Proxy Client

    T->>S: Execute testPermanentRedirect()
    S->>Site: Initialize site with parameters
    Site-->>S: Return site created (HTTP 200)
    S->>Site: Setup domain and create deployment
    Site-->>S: Deployment created (HTTP 200)
    S->>Proxy: GET request to "/"
    Proxy-->>S: 200 OK response
    S->>Proxy: GET request to "/project1/"
    Proxy-->>S: 200 OK response
    S->>T: Cleanup site and conclude test
Loading

Suggested reviewers

  • Meldiron

Poem

I'm a rabbit in the code, hopping through the night,
Testing site redirects with all my might.
Domains set, deployments made with glee,
HTML in subdirectories, plain to see.
With a twitch of my nose and a joyous hop,
I celebrate the changes that never stop!
🥕🌟 Hop on, the journey's at the top!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e0a6f9 and 9404e92.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • tests/e2e/Services/Sites/SitesCustomServerTest.php (1 hunks)
  • tests/resources/sites/sub-directories/index.html (1 hunks)
  • tests/resources/sites/sub-directories/project1/index.html (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • tests/resources/sites/sub-directories/index.html
  • tests/resources/sites/sub-directories/project1/index.html
🧰 Additional context used
🧬 Code Definitions (1)
tests/e2e/Services/Sites/SitesCustomServerTest.php (2)
tests/e2e/Services/Sites/SitesBase.php (3)
  • setupSite (20-33)
  • setupSiteDomain (329-347)
  • setupDeployment (35-67)
tests/e2e/Client.php (2)
  • Client (8-317)
  • call (167-277)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (1)
tests/e2e/Services/Sites/SitesCustomServerTest.php (1)

2433-2466: Good implementation of the 308 permanent redirect test!

The test properly validates that both /project1 and /project1/ URLs return a 200 status code with the expected content. This ensures that the permanent redirect from paths without a trailing slash to paths with a trailing slash (or vice versa) works correctly.

I notice that the test is checking both paths by verifying:

  1. The response status code is 200
  2. The response body contains the expected content

One small suggestion to make the test even more comprehensive would be to explicitly check that a request to /project1 without a trailing slash gets redirected with a 308 status code before eventually returning a 200. This could be done by setting followRedirects: false in the proxy client call.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

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.
< 8000 /form>

Copy link
github-actions bot commented Mar 21, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
@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: 0

🧹 Nitpick comments (1)
tests/e2e/Services/Sites/SitesCustomServerTest.php (1)

2334-2370: LGTM! Well-implemented test for permanent redirect functionality.

The test method is well-structured, properly following the established testing patterns in this class. It appropriately:

  1. Sets up a site with required parameters
  2. Verifies site creation
  3. Sets up domain and deployment
  4. Tests relevant HTTP responses for different paths
  5. Verifies the 308 status code for the trailing slash redirect
  6. Cleans up resources after testing

Consider enhancing the test by also verifying the Location header in the redirect response to ensure it points to the correct destination URL. This would provide more complete validation of the redirect behavior.

- $response2 = $proxyClient->call(Client::METHOD_GET, '/project1/');
- $this->assertEquals(308, $response2['headers']['status-code']);
+ $response2 = $proxyClient->call(Client::METHOD_GET, '/project1/');
+ $this->assertEquals(308, $response2['headers']['status-code']);
+ $this->assertArrayHasKey('location', $response2['headers']);
+ $this->assertEquals('/project1', $response2['headers']['location']);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c323c22 and 65aa218.

📒 Files selected for processing (4)
  • tests/e2e/Services/Sites/SitesCustomServerTest.php (1 hunks)
  • tests/resources/sites/subProjects/index.html (1 hunks)
  • tests/resources/sites/subProjects/project1/index.html (1 hunks)
  • tests/resources/sites/subProjects/project2/index.html (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
tests/e2e/Services/Sites/SitesCustomServerTest.php (3)
tests/e2e/Services/Sites/SitesBase.php (4) (4)
  • setupSite (20-33)
  • getSite (161-169)
  • setupSiteDomain (329-347)
  • setupDeployment (35-67)
tests/e2e/Services/Functions/FunctionsBase.php (1) (1)
  • setupDeployment (35-67)
src/Executor/Executor.php (1) (1)
  • call (290-416)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (3)
tests/resources/sites/subProjects/project1/index.html (1)

1-13: LGTM! Well-structured HTML file for Project 1.

The HTML structure is clean and correctly formatted with all necessary elements - proper doctype, meta tags for charset and viewport, appropriate title, and a well-organized body with heading, welcome text, and navigation link back to the main page.

tests/resources/sites/subProjects/project2/index.html (1)

1-13: LGTM! Well-structured HTML file for Project 2.

The HTML structure is clean and correctly formatted with all necessary elements - proper doctype, meta tags for charset and viewport, appropriate title, and a well-organized body with heading, welcome text, and navigation link back to the main page.

tests/resources/sites/subProjects/index.html (1)

1-17: LGTM! Well-structured main index HTML file.

The HTML structure is clean and correctly formatted with appropriate navigation to the sub-projects. The use of an unordered list for project links provides good semantic structure.

Copy link
github-actions bot commented Mar 21, 2025

✨ Benchmark results

  • Requests per second: 923
  • Requests with 200 status code: 166,174
  • P99 latency: 0.201264425

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 923 1,347
200 166,174 242,538
P99 0.201264425 0.136450089

Copy link
@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: 0

🧹 Nitpick comments (4)
tests/e2e/Services/Sites/SitesCustomServerTest.php (4)

2397-2432: LGTM for basic redirect testing, consider enhanced assertions for 308 redirect validation.

The test successfully verifies that both paths ('/project1' and '/project1/') return 200 status codes, confirming basic redirect functionality is working. However, if the specific goal is to test 308 permanent redirects, consider improving the test with the following enhancements:

  1. Add redirect-specific assertions by setting followRedirects: false to observe the actual redirect status code:
-$response1 = $proxyClient->call(Client::METHOD_GET, '/project1');
-$this->assertEquals(200, $response1['headers']['status-code']);
+$response1 = $proxyClient->call(Client::METHOD_GET, '/project1', followRedirects: false);
+$this->assertEquals(308, $response1['headers']['status-code']);
+$this->assertArrayHasKey('location', $response1['headers']);
+$this->assertEquals('/project1/', $response1['headers']['location']);
+
+// Test the redirected URL directly
+$response1Redirected = $proxyClient->call(Client::METHOD_GET, '/project1/');
+$this->assertEquals(200, $response1Redirected['headers']['status-code']);
  1. Consider checking response body content to verify the correct page is loaded:
$response2 = $proxyClient->call(Client::METHOD_GET, '/project1/');
$this->assertEquals(200, $response2['headers']['status-code']);
+$this->assertStringContainsString('Project 1', $response2['body']);<
8000
/span>

2410-2410: Use integer for status code comparison instead of string.

For consistency with the rest of the codebase, use an integer value (200) instead of a string ('200') when comparing status codes.

-$this->assertEquals('200', $site['headers']['status-code']);
+$this->assertEquals(200, $site['headers']['status-code']);

2417-2417: Use boolean instead of string for 'activate' parameter.

For consistency with other places in the codebase, consider using a boolean true instead of the string 'true'.

-    'activate' => 'true'
+    'activate' => true

2421-2421: Remove unused site retrieval or add assertions.

This line retrieves the site details but doesn't use the returned value. Either remove it or add assertions to verify expected site properties after deployment.

-$site = $this->getSite($siteId);
+// Either remove this line or add assertions, for example:
+$site = $this->getSite($siteId);
+$this->assertNotEmpty($site['body']['deploymentId']);
+$this->assertEquals($deploymentId, $site['body']['deploymentId']);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65aa218 and 2e0a6f9.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • tests/e2e/Services/Sites/SitesCustomServerTest.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Setup & Build Appwrite Image

@Meldiron Meldiron merged commit aedfe03 into feat-sites Mar 27, 2025
80 of 83 checks passed
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
0