-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
SecGeoLookupDb directive support #170
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c1a84f5
add support for geoip
syinwu f4f6c5c
supprot multiple geoip engines and optimize gh actions
syinwu ef0580c
update regression.yml
syinwu 734ae3b
fix regression.yml
syinwu 9222c4f
fix regression.yml
syinwu 3a5f88b
fix regression.yml
syinwu a7facd4
use secret keys in CI for geoip testing
syinwu 8e2f16d
add test for args combined size limit and file combined size limit
syinwu a698f04
use git lfs
syinwu 0bea2b6
fix test cases
syinwu 595f6f3
fix lint workflow
syinwu 0a1edf6
fix ip2location test cases
syinwu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
testdata/geoip_db/IP2LOCATION-LITE-DB11.IPV6.BIN filter=lfs diff=lfs merge=lfs -text | ||
testdata/geoip_db/GeoLite2-City.mmdb filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package operators | ||
|
||
import ( | ||
engine "github.com/corazawaf/coraza/v2" | ||
"github.com/corazawaf/coraza/v2/types/variables" | ||
"github.com/corazawaf/coraza/v2/utils/geoip" | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func Test_geoLookup(t *testing.T) { | ||
geoLookupTest := geoLookup{} | ||
if err := geoLookupTest.Init(""); err != nil { | ||
t.Errorf("Error init geolookup") | ||
} | ||
|
||
var err error | ||
waf := engine.NewWaf() | ||
db := &geoip.MaxMinddb{} | ||
err = db.Init("../testdata/geoip_db/GeoLite2-City.mmdb") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
waf.GeoDB = db | ||
if err != nil { | ||
t.Errorf("geoip db init error: %s", err) | ||
} | ||
|
||
tx := waf.NewTransaction() | ||
if !geoLookupTest.Evaluate(tx, "81.2.69.142") { | ||
t.Errorf("Invalid result for @geoLookup operator") | ||
} | ||
|
||
if tx.GetCollection(variables.Geo).GetFirstString(countryCode) != "GB" { | ||
t.Errorf("Invalid `COUNTRY_CODE` key for @geoLookup operator") | ||
} | ||
|
||
if tx.GetCollection(variables.Geo).GetFirstString(countryName) != "United Kingdom" { | ||
t.Errorf("Invalid `COUNTRY_NAME` key for @geoLookup operator") | ||
} | ||
|
||
if tx.GetCollection(variables.Geo).GetFirstString(countryContinent) != "Europe" { | ||
t.Errorf("Invalid `COUNTRY_CONTINENT` key for @geoLookup operator") | ||
} | ||
|
||
if tx.GetCollection(variables.Geo).GetFirstString(city) != "Chingford" { | ||
t.Errorf("Invalid `CITY` key for @geoLookup operator") | ||
} | ||
|
||
if tx.GetCollection(variables.Geo).GetFirstString(postalCode) != "E4" { | ||
t.Errorf("Invalid `POSTAL_CODE` key for @geoLookup operator") | ||
} | ||
|
||
latitude, err := strconv.ParseFloat(tx.GetCollection(variables.Geo).GetFirstString(latitude), 64) | ||
if err != nil { | ||
t.Errorf("latitude data parse error: %s", err.Error()) | ||
} | ||
if latitude != 51.6311 { | ||
t.Errorf("Invalid `LATITUDE` key for @geoLookup operator") | ||
} | ||
|
||
longitude, err := strconv.ParseFloat(tx.GetCollection(variables.Geo).GetFirstString(longitude), 64) | ||
if err != nil { | ||
t.Errorf("longitude data parse error: %s", err.Error()) | ||
} | ||
if longitude != 0.0018 { | ||
t.Errorf("Invalid `LONGITUDE` key for @geoLookup operator") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure ge, eq, lt, etc... support floats instead of ints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah! Using float64 can support the comparison of positive and negative numbers, and the memory occupied on 64 bit machines is the same as that of int type(most machines should be 64 bit)