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 Alias @pmf for @pmFromFile #1291

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

satwiksps
Copy link

@satwiksps satwiksps commented Jan 22, 2025

Add Alias @pmf for @pmFromFile

Description

This pull request introduces the short alias @pmf for the operator @pmFromFile in accordance with the documentation. The alias provides a shorthand for users while maintaining the same functionality as @pmFromFile.

Changes Made

  1. Alias Registration:

    • Added @pmf alias to the pmFromFile operator by updating the Register() call in the pm_from_file.go file.
  2. Test Suite:

    • Introduced a new test case in pm_from_file_test.go to validate both @pmFromFile and its alias @pmf.
    • Tests include:
      • Valid inputs
      • Invalid inputs
      • Missing file handling
    • Mocked the loadFromFile function for unit testing without requiring actual files.

Motivation

The @pmf alias was described in the documentation but was missing in the implementation. This PR aligns the implementation with the documentation and improves usability by providing a shorthand for @pmFromFile.

Testing

  • Verified that both @pmFromFile and @pmf operators work as expected:
    • Properly match patterns loaded from files.
    • Return expected results for valid and invalid inputs.
    • Handle missing or invalid files gracefully.
  • Added unit tests using go test to ensure robust validation of functionality.

Related Issues

Checklist

  • Updated the test suite with cases for @pmf.
  • Implemented the @pmf alias in the code.
  • Ran all tests to verify correctness.

@satwiksps satwiksps requested a review from a team as a code owner January 22, 2025 16:06
Copy link

codecov bot commented Jan 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 16.55%. Comparing base (62e8e79) to head (13d71ef).

❗ There is a different number of reports uploaded between BASE (62e8e79) and HEAD (13d71ef). Click for more details.

HEAD has 351 uploads less than BASE
Flag BASE (62e8e79) HEAD (13d71ef)
default 32 1
tinygo 16 0
coraza.rule.no_regex_multiline 48 0
coraza.rule.multiphase_valuation 54 0
memoize_builders 44 0
examples+coraza.rule.no_regex_multiline 8 0
examples+coraza.rule.case_sensitive_args_keys 16 0
no_fs_access 55 0
coraza.rule.case_sensitive_args_keys 40 0
ftw 32 0
examples+coraza.rule.multiphase_valuation 2 0
examples+memoize_builders 4 0
examples+no_fs_access 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1291       +/-   ##
===========================================
- Coverage   81.76%   16.55%   -65.21%     
===========================================
  Files         169      149       -20     
  Lines        9770     8968      -802     
===========================================
- Hits         7988     1485     -6503     
- Misses       1533     7300     +5767     
+ Partials      249      183       -66     
Flag Coverage Δ
coraza.rule.case_sensitive_args_keys ?
coraza.rule.multiphase_valuation ?
coraza.rule.no_regex_multiline ?
default 16.55% <100.00%> (-65.21%) ⬇️
examples+ 16.55% <100.00%> (+<0.01%) ⬆️
examples+coraza.rule.case_sensitive_args_keys ?
examples+coraza.rule.multiphase_valuation ?
examples+coraza.rule.no_regex_multiline ?
examples+memoize_builders ?
examples+no_fs_access ?
ftw ?
memoize_builders ?
no_fs_access ?
tinygo ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jptosso
Copy link
Member

jptosso commented Jan 22, 2025

Thank you for your contribution. I don't think we need new tests for pmfromfile, we should just test that the pmFromFile pointer is the same as pm

@satwiksps
Copy link
Author

Thank you for your contribution. I don't think we need new tests for pmfromfile, we should just test that the pmFromFile pointer is the same as pm

Add Alias for pmFromFile and Validate Equivalence with pm

  • Implemented the @pmf alias for pmFromFile as described in the documentation.
  • Added a test to confirm that pmFromFile behaves identically to pm (shared behavior and logic).
  • Removed redundant tests for pmFromFile to avoid duplication.

I am new to Open Source Contributions.
Please guide me if I need to make any additional changes.

@M4tteoP
Copy link
Member

M4tteoP commented Jan 22, 2025

Hi, thanks for the PR! Some CI tests are failing:

  • the linter: for this one you probably have to format the new file created. To do so you can run mage format from the top directory of the project. Then, you can locally check with mage lint to see if everything passes
internal/operators/pm_from_file.go:54: File is not `gofmt`-ed with `-s` (gofmt)
    Register("pmFromFile", newPMFromFile)
    Register("pmf", newPMFromFile)
internal/operators/pm_from_file_test.go:1: File is not `gofmt`-ed with `-s` (gofmt)
package operators
internal/operators/pm_from_file_test.go:[5](https://github.com/corazawaf/coraza/actions/runs/12913855172/job/36012093907?pr=1291#step:4:6): File is not `goimports`-ed (goimports)
    "github.com/corazawaf/coraza/v3/experimental/plugins/plugintypes"
exit status 1
Error: running "go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.[6](https://github.com/corazawaf/coraza/actions/runs/12913855172/job/36012093907?pr=1291#step:4:7)0.3 run" failed with exit code 1
exit status 1
  • The added test:
--- FAIL: TestPmFromFileAlias (0.00s)
    pm_from_file_test.go:20: Failed to initialize pmFromFile: empty dirs
FAIL

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.

Missing @pmf short alias for @pmFromFile
3 participants