rustypaste/fixtures
Ömer Üstün 95379c9f66
feat(server): support handling spaces in filenames (#107)
* feat(server): add url encoding

- Introduced an option to enable encoding for filenames in the returned URL.
- Modified the encoding approach to specifically target whitespaces, replacing them with `%20`.
- Included unit tests to validate this encoding approach.
- Added fixture tests for broader functional verification.
- Removed the `urlencoding` dependency from `Cargo.toml`.

* Refactor code and fixtures for better compliance and consistency

- Fixed errors in the fixture configuration to ensure tests run as expected.
- Reformatted line endings for consistency across the codebase.
- Made necessary adjustments to adhere to Clippy's recommendations.

* Enhance whitespace handling options for filenames

- Implemented a configuration choice for space handling in filenames: encode, replace with underscores or none.
- Added corresponding unit and fixture tests.

* Remove redundant function call

Fixed misplaced line as per @tessus's review feedback, preventing duplicate handling of spaces in filenames.

* Delete test file with spaces.txt

* Refactor filename space handling

- Introduced `SpaceHandling` enum to manage filename spaces.
- Updated server.rs and paste.rs to utilize the new method.
- Added unit tests for the new filename handling method.
- Adjusted fixture tests to reflect these changes.

* Move filename processing into `SpaceHandling` enum

- Relocated filename processing logic to reside within the `SpaceHandling` enum, enhancing encapsulation.
- Updated calls in `server.rs` and `paste.rs` to use the new method structure.
- Adjusted unit tests to align with the refactored function location and call pattern.

* Refactor based on review suggestions

- Incorporated the inline suggestions made by @tessus, removing the unnecessary one-line assignments.
- Ensured the code adheres to Rust guidelines by running clippy and fmt.

* chore(deps): revert changes in Cargo.lock

* chore(config): replace spaces as default

* refactor(config): move SpaceHandling to config module

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2023-08-26 14:35:13 +02:00
..
test-duplicate-file-upload feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-expiring-file-upload feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-file-upload feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-filename-replace feat(server): support handling spaces in filenames (#107) 2023-08-26 14:35:13 +02:00
test-list-files feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-oneshot-upload feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-oneshot-url feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-path-traversal feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-random-suffix feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-random-url feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-remote-file-upload feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-server-auth feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-server-auth-multiple-tokens feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-server-auto-deletion feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-server-default-extension feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-server-landing-page feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-server-landing-page-file feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-server-mime-blacklist feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-server-mime-override feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-server-payload-limit feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
test-url-encode feat(server): support handling spaces in filenames (#107) 2023-08-26 14:35:13 +02:00
test-url-upload feat(server): improve random_url config handling (#122) 2023-08-20 20:32:41 +02:00
.env test(fixtures): add a test framework along with test fixtures 2022-05-21 15:27:38 +03:00
README.md refactor(fixtures): use subshell for running fixture methods 2022-05-21 16:51:06 +03:00
test-fixtures.sh refactor(fixtures): merge test steps in a single subshell 2022-05-21 17:52:47 +03:00

README.md

Fixtures

This directory contains the test fixtures and a simple testing framework for rustypaste.

Running fixtures

  1. Build the project in debug mode: cargo build
  2. Execute the runner script in this directory: ./test-fixtures.sh

Adding new fixtures

Create an appropriately named directory for the test fixture you want to add. e.g. test-file-upload

Each fixture directory should contain the following files:

test-file-upload/
├── config.toml
└── test.sh
  • config.toml: Contains the rustypaste configuration. See the default configuration.
  • test.sh: Contains the helper functions for testing. The file format is the following:
#!/usr/bin/env bash

setup() {
  # preparation
}

run_test() {
  # assertions
}

teardown() {
  # cleanup
}

These functions are executed in the order defined above.

See the test-file-upload fixture for an example.

Debugging

Set the DEBUG environment variable to true while executing the runner script:

$ DEBUG=true ./test-fixtures.sh