Skip to content

Commit

Permalink
Merge branch 'main' into refactor/general-refactor
Browse files Browse the repository at this point in the history
# Conflicts:
#	es/range.go
  • Loading branch information
GokselKUCUKSAHIN committed Jan 16, 2025
2 parents a899fef + 86981ae commit 7996bcd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 19 deletions.
33 changes: 33 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Security Policy

## Supported Versions

The following versions of `es-query-builder` are currently supported with security updates:

| Version | Supported |
| -------- | ------------------ |
| ≥ 0.3.6 | ✅ Supported |
| < 0.3.6 | ❌ Not Supported |

## Reporting a Vulnerability

We encourage the community to report security vulnerabilities responsibly to help us maintain the integrity of `es-query-builder`.

### Public Reporting
- For most issues, please create a **GitHub Issue** in the [repository Issues section](https://github.com/Trendyol/es-query-builder/issues).
- Include the following details in your report:
- A description of the vulnerability.
- Steps to reproduce the issue.
- (Optional) Your suggestions for mitigation or fixes.

### Private Reporting
If the vulnerability is sensitive and public disclosure could pose a risk, please report it privately by using GitHub's [private security advisory feature](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability).

### What to Expect
1. **Acknowledgment**: We will respond to your report within **48 hours**.
2. **Resolution Process**:
- Accepted vulnerabilities will be assigned a severity level and prioritized.
- A fix is typically delivered within **30 days**, depending on severity.
3. **Confidentiality**: Please avoid sharing the vulnerability details publicly until a fix has been released.

We appreciate your contributions to keeping `es-query-builder` secure!
2 changes: 1 addition & 1 deletion benchmarks/tests/aggs_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func createAggsQuery() map[string]any {
es.Term("type", "File"),
es.Range("indexedAt").
GreaterThan("2020-06-01").
LesserThanOrEqual("now"),
LessThanOrEqual("now"),
).
MustNot(
es.Exists("file.name"),
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/tests/complex_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func createComplexQuery(id int) map[string]any {
Must(
es.Range("partition").
GreaterThan(25).
LesserThanOrEqual(30),
LessThanOrEqual(30),
es.Bool().
Should(
es.Term("doc.id", id),
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/tests/conditional_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func createConditionalQuery(items []int) map[string]any {
Filter(
es.Range("indexedAt").
GreaterThan("2021-01-01").
LesserThanOrEqual("now"),
LessThanOrEqual("now"),
es.Term("type", "File"),
es.Terms("sector", 1, 2, 3),
es.TermsFunc("id", items, func(key string, values []int) bool {
Expand Down
12 changes: 6 additions & 6 deletions es/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func Range(key string) rangeType {
}
}

// LesserThan sets the "lt" (less than) field for the range query.
// LessThan sets the "lt" (less than) field for the range query.
//
// This method specifies that the range query should match values that are less than
// the provided value. It removes any existing "lte" (less than or equal to) field to ensure
// that only one type of range condition is applied.
//
// Example usage:
//
// r := es.Range("age").LesserThan(20)
// r := es.Range("age").LessThan(20)
// // r now has an "lt" field set to 20 in the range query for the "age" field.
//
// Parameters:
Expand All @@ -45,19 +45,19 @@ func Range(key string) rangeType {
// Returns:
//
// The updated es.rangeType object with the "lt" field set to the specified value.
func (r rangeType) LesserThan(lt any) rangeType {
func (r rangeType) LessThan(lt any) rangeType {
return r.putInTheField("lt", lt).delete("lte")
}

// LesserThanOrEqual sets the "lte" (less than or equal to) field for the range query.
// LessThanOrEqual sets the "lte" (less than or equal to) field for the range query.
//
// This method specifies that the range query should match values that are less than or equal
// to the provided value. It removes any existing "lt" (less than) field to ensure that only
// one type of range condition is applied.
//
// Example usage:
//
// r := es.Range("age").LesserThanOrEqual(20)
// r := es.Range("age").LessThanOrEqual(20)
// // r now has an "lte" field set to 20 in the range query for the "age" field.
//
// Parameters:
Expand All @@ -66,7 +66,7 @@ func (r rangeType) LesserThan(lt any) rangeType {
// Returns:
//
// The updated es.rangeType object with the "lte" field set to the specified value.
func (r rangeType) LesserThanOrEqual(lte any) rangeType {
func (r rangeType) LessThanOrEqual(lte any) rangeType {
return r.putInTheField("lte", lte).delete("lt")
}

Expand Down
20 changes: 10 additions & 10 deletions es/range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Test_Range_should_add_range_field_when_inside_query(t *testing.T) {
Must(
es.Range("age").
GreaterThanOrEqual(10).
LesserThanOrEqual(20),
LessThanOrEqual(20),
es.Term("language", "tr"),
),
)
Expand Down Expand Up @@ -51,7 +51,7 @@ func Test_Range_should_create_json_with_range_field_inside_query(t *testing.T) {
query := es.NewQuery(
es.Range("age").
GreaterThanOrEqual(10).
LesserThanOrEqual(20),
LessThanOrEqual(20),
)

// When Then
Expand All @@ -60,22 +60,22 @@ func Test_Range_should_create_json_with_range_field_inside_query(t *testing.T) {
assert.Equal(t, "{\"query\":{\"range\":{\"age\":{\"gte\":10,\"lte\":20}}}}", bodyJSON)
}

func Test_Range_should_have_LesserThan_method(t *testing.T) {
func Test_Range_should_have_LessThan_method(t *testing.T) {
// Given
r := es.Range("age")

// When Then
assert.NotNil(t, r)
assert.NotNil(t, r.LesserThan)
assert.NotNil(t, r.LessThan)
}

func Test_Range_should_have_LesserThanOrEqual_method(t *testing.T) {
func Test_Range_should_have_LessThanOrEqual_method(t *testing.T) {
// Given
r := es.Range("age")

// When Then
assert.NotNil(t, r)
assert.NotNil(t, r.LesserThanOrEqual)
assert.NotNil(t, r.LessThanOrEqual)
}

func Test_Range_should_have_GreaterThan_method(t *testing.T) {
Expand Down Expand Up @@ -114,8 +114,8 @@ func Test_Range_lte_should_override_lt_and_vise_versa(t *testing.T) {
// Given
query := es.NewQuery(
es.Range("age").
LesserThan(11).
LesserThanOrEqual(23),
LessThan(11).
LessThanOrEqual(23),
)

// When Then
Expand All @@ -138,7 +138,7 @@ func Test_Range_Format_should_create_json_with_range_field_inside_query(t *testi
query := es.NewQuery(
es.Range("birth-date").
GreaterThanOrEqual("1990-01-01").
LesserThanOrEqual("2024-04-12").
LessThanOrEqual("2024-04-12").
Format("yyyy-MM-dd"),
)

Expand All @@ -163,7 +163,7 @@ func Test_Range_Boost_should_create_json_with_range_field_inside_query(t *testin
query := es.NewQuery(
es.Range("partition").
GreaterThan(112).
LesserThan(765).
LessThan(765).
Boost(3.2),
)

Expand Down

0 comments on commit 7996bcd

Please sign in to comment.