nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: avenga/couper
Pull request #32 (2020-09-29 14:09:27)

Fix: do not try to parse a rsa key if algo is hmac


Patch:
diff --git a/accesscontrol/jwt.go b/accesscontrol/jwt.go
index 78d10109..09927507 100644
--- a/accesscontrol/jwt.go
+++ b/accesscontrol/jwt.go
@@ -82,6 +82,10 @@ func NewJWT(algorithm, name string, claims Claims, reqClaims []string, src Sourc
 		sourceKey:      srcKey,
 	}
 
+	if algo.IsHMAC() {
+		return jwtObj, nil
+	}
+
 	pubKey, err := parsePublicPEMKey(key)
 	if err != nil && (err != jwt.ErrKeyMustBePEMEncoded || err != jwt.ErrNotRSAPublicKey) {
 		cert, err := x509.ParseCertificate(key)
diff --git a/accesscontrol/jwt_algorithm.go b/accesscontrol/jwt_algorithm.go
index 084fd632..a157b7f1 100644
--- a/accesscontrol/jwt_algorithm.go
+++ b/accesscontrol/jwt_algorithm.go
@@ -30,6 +30,15 @@ func NewAlgorithm(a string) Algorithm {
 	}
 }
 
+func (a Algorithm) IsHMAC() bool {
+	switch a {
+	case AlgorithmHMAC256, AlgorithmHMAC384, AlgorithmHMAC512:
+		return true
+	default:
+		return false
+	}
+}
+
 func (a Algorithm) String() string {
 	switch a {
 	case AlgorithmRSA256:


Test patch:
diff --git a/accesscontrol/jwt_test.go b/accesscontrol/jwt_test.go
index ad7a785d..558b2709 100644
--- a/accesscontrol/jwt_test.go
+++ b/accesscontrol/jwt_test.go
@@ -8,7 +8,6 @@ import (
 	"fmt"
 	"net/http"
 	"net/http/httptest"
-	"strings"
 	"testing"
 
 	"github.com/dgrijalva/jwt-go/v4"
@@ -40,12 +39,14 @@ func TestJWT_Validate(t *testing.T) {
 		var token string
 		var tokenErr error
 
-		if strings.HasPrefix(signingMethod.Alg(), "HS") {
+		algo := ac.NewAlgorithm(signingMethod.Alg())
+
+		if algo.IsHMAC() {
+			pubKeyBytes = []byte("mySecretK3y")
 			token, tokenErr = tok.SignedString(pubKeyBytes)
-		} else if strings.HasPrefix(signingMethod.Alg(), "RS") {
+		} else {
 			token, tokenErr = tok.SignedString(privKey)
 		}
-		algo := ac.NewAlgorithm(signingMethod.Alg())
 
 		if tokenErr != nil {
 			t.Error(tokenErr)
Repository: avenga/couper
Pull request #45 (2020-10-07 15:14:05)

Fix wildcard path join with trailing slash
This will fix a wrong behaviour for wildcard path rewrites:

```hcl
api {
    base_path = "/api"

    backend {
      #inline
    }

    endpoint "/doc/**" {
      path = "/doc/**"
    }
}
```

which results in  `bereq.path: /doc` . Expected `/doc/` if `req.path` is `/api/doc/`


Patch:
diff --git a/handler/proxy.go b/handler/proxy.go
index 5e80ad25..bba6f458 100644
--- a/handler/proxy.go
+++ b/handler/proxy.go
@@ -10,7 +10,6 @@ import (
 	"net"
 	"net/http"
 	"net/url"
-	"path"
 	"strconv"
 	"strings"
 	"time"
@@ -26,6 +25,7 @@ import (
 	"github.com/avenga/couper/eval"
 	"github.com/avenga/couper/internal/seetie"
 	"github.com/avenga/couper/logging"
+	"github.com/avenga/couper/utils"
 )
 
 var (
@@ -284,7 +284,7 @@ func (p *Proxy) director(req *http.Request) {
 
 	if pathMatch, ok := req.Context().
 		Value(request.Wildcard).(string); ok && strings.HasSuffix(p.options.Path, "/**") {
-		req.URL.Path = path.Join(strings.ReplaceAll(p.options.Path, "/**", "/"), pathMatch)
+		req.URL.Path = utils.JoinPath(strings.ReplaceAll(p.options.Path, "/**", "/"), pathMatch)
 	} else if p.options.Path != "" {
 		req.URL.Path = p.options.Path
 	}


Test patch:
diff --git a/handler/proxy_test.go b/handler/proxy_test.go
index 66729100..30e81a36 100644
--- a/handler/proxy_test.go
+++ b/handler/proxy_test.go
@@ -403,6 +403,7 @@ func TestProxy_director(t *testing.T) {
 		{"proxy url settings", fields{eval.NewENVContext(nil), log.WithContext(nil), &ProxyOptions{Origin: "http://1.2.3.4", Context: emptyOptions}}, defaultReq, httptest.NewRequest("GET", "http://1.2.3.4", nil)},
 		{"proxy url settings w/hostname", fields{eval.NewENVContext(nil), log.WithContext(nil), &ProxyOptions{Origin: "http://1.2.3.4", Hostname: "couper.io", Context: emptyOptions}}, defaultReq, httptest.NewRequest("GET", "http://couper.io", nil)},
 		{"proxy url settings w/wildcard ctx", fields{eval.NewENVContext(nil), log.WithContext(nil), &ProxyOptions{Origin: "http://1.2.3.4", Hostname: "couper.io", Path: "/**", Context: emptyOptions}}, defaultReq.WithContext(context.WithValue(defaultReq.Context(), request.Wildcard, "/hans")), httptest.NewRequest("GET", "http://couper.io/hans", nil)},
+		{"proxy url settings w/wildcard ctx trailing slash", fields{eval.NewENVContext(nil), log.WithContext(nil), &ProxyOptions{Origin: "http://1.2.3.4", Hostname: "couper.io", Path: "/**", Context: emptyOptions}}, defaultReq.WithContext(context.WithValue(defaultReq.Context(), request.Wildcard, "/docs/")), httptest.NewRequest("GET", "http://couper.io/docs/", nil)},
 	}
 
 	for _, tt := range tests {
Repository: avenga/couper
Pull request #56 (2020-10-23 13:04:37)

Fix a panic for unknown cty types, fallback to cty.NullVal(cty.String)


Patch:
diff --git a/internal/seetie/convert.go b/internal/seetie/convert.go
index 05051a80..1184b060 100644
--- a/internal/seetie/convert.go
+++ b/internal/seetie/convert.go
@@ -5,7 +5,6 @@ import (
 	"math/big"
 	"net/http"
 	"net/url"
-	"reflect"
 	"regexp"
 	"strconv"
 	"strings"
@@ -81,7 +80,7 @@ func GoToValue(v interface{}) cty.Value {
 	case map[string]interface{}:
 		return MapToValue(v.(map[string]interface{}))
 	}
-	return cty.NilVal
+	return cty.NullVal(cty.String)
 }
 
 func MapToValue(m map[string]interface{}) cty.Value {
@@ -96,8 +95,6 @@ func MapToValue(m map[string]interface{}) cty.Value {
 			continue
 		}
 		switch v.(type) {
-		case bool, float64, string:
-			ctyMap[k] = GoToValue(v)
 		case []string:
 			var list []interface{}
 			for _, s := range v.([]string) {
@@ -109,7 +106,7 @@ func MapToValue(m map[string]interface{}) cty.Value {
 		case map[string]interface{}:
 			ctyMap[k] = MapToValue(v.(map[string]interface{}))
 		default:
-			panic(reflect.TypeOf(v).String() + " not implemented")
+			ctyMap[k] = GoToValue(v)
 		}
 	}
 
@@ -168,6 +165,10 @@ var whitespaceRegex = regexp.MustCompile(`^\s*$`)
 // ValueToString explicitly drops all other (unknown) types and
 // converts non whitespace strings or numbers to its string representation.
 func ValueToString(v cty.Value) string {
+	if v.IsNull() {
+		return ""
+	}
+
 	switch v.Type() {
 	case cty.String:
 		str := v.AsString()
@@ -221,6 +222,9 @@ func ToString(s interface{}) string {
 
 // isTuple checks by type name since tuple is not comparable by type.
 func isTuple(v cty.Value) bool {
+	if v.IsNull() {
+		return false
+	}
 	return v.Type().FriendlyNameForConstraint() == "tuple"
 }
 


Test patch:
diff --git a/eval/context_test.go b/eval/context_test.go
index 385ed7d2..47713492 100644
--- a/eval/context_test.go
+++ b/eval/context_test.go
@@ -78,6 +78,10 @@ func TestNewHTTPContext(t *testing.T) {
 			method = req.method
 			title = req.json_body.slice.foo
 		`, http.Header{"method": {http.MethodGet}}},
+		{"Variables / GET /w json body & null value", http.MethodGet, http.Header{"Content-Type": {"application/json"}}, bytes.NewBufferString(`{"json": null}`), "", baseCtx, `
+			method = req.method
+			title = req.json_body.json
+		`, http.Header{"method": {http.MethodGet}, "title": {""}}},
 	}
 
 	log, _ := test.NewNullLogger()
@@ -134,7 +138,7 @@ func TestNewHTTPContext(t *testing.T) {
 
 				result := seetie.ValueToStringSlice(cv)
 				if !reflect.DeepEqual(v, result) {
-					t.Errorf("Expected %q, got: %v", v, cv)
+					t.Errorf("Expected %q, got: %#v", v, cv)
 				}
 			}
 		})
Repository: avenga/couper
Pull request #204 (2021-04-13 07:36:49)

Fix args filtering


Patch:
diff --git a/command/flag.go b/command/flag.go
index 287b9a10..91f2379e 100644
--- a/command/flag.go
+++ b/command/flag.go
@@ -30,7 +30,13 @@ func (a Args) Filter(set *flag.FlagSet) Args {
 						continue
 					}
 				}
-				args = append(args, a[i:i+2]...)
+
+				if len(a[i:]) > 1 {
+					args = append(args, a[i:i+2]...)
+				} else {
+					args = append(args, a[i:i+1]...)
+				}
+
 				continue
 			}
 			args = append(args, a[i])


Test patch:
diff --git a/main_test.go b/main_test.go
index 4ab79107..13189136 100644
--- a/main_test.go
+++ b/main_test.go
@@ -32,6 +32,7 @@ func Test_realmain(t *testing.T) {
 		{"common log format via env /w file", []string{"couper", "run", "-f", base + "/log_json.hcl"}, []string{"COUPER_LOG_FORMAT=common"}, `level=error msg="configuration error: missing server definition" build=dev`, 1},
 		// TODO: format from file currently not possible due to the server error
 		{"json log format via env /w file", []string{"couper", "run", "-f", base + "/log_common.hcl"}, []string{"COUPER_LOG_FORMAT=json"}, `{"build":"dev","level":"error","message":"configuration error: missing server definition"`, 1},
+		{"-f w/o file", []string{"couper", "run", "-f"}, nil, `level=error msg="flag needs an argument: -f" build=dev`, 1},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
Repository: avenga/couper
Pull request #207 (2021-04-14 07:36:19)

allow other json mime types


Patch:
diff --git a/eval/context.go b/eval/context.go
index 145461b0..a4c2eba9 100644
--- a/eval/context.go
+++ b/eval/context.go
@@ -10,6 +10,7 @@ import (
 	"net/url"
 	"os"
 	"strconv"
+	"strings"
 	"time"
 
 	"github.com/hashicorp/hcl/v2"
@@ -228,7 +229,8 @@ func parseForm(r *http.Request) *http.Request {
 
 func isJSONMediaType(contentType string) bool {
 	m, _, _ := mime.ParseMediaType(contentType)
-	return m == "application/json"
+	mParts := strings.Split(m, "/")
+	return len(mParts) == 2 && mParts[0] == "application" && (mParts[1] == "json" || strings.HasSuffix(mParts[1], "+json"))
 }
 
 func parseJSON(r io.Reader) cty.Value {


Test patch:
diff --git a/handler/endpoint_test.go b/handler/endpoint_test.go
index ebbd68d2..13187fa3 100644
--- a/handler/endpoint_test.go
+++ b/handler/endpoint_test.go
@@ -165,7 +165,7 @@ func TestEndpoint_RoundTripContext_Variables_json_body(t *testing.T) {
 		origin = "` + origin.URL + `"
 		set_request_headers = {
 			x-test = request.json_body.foo
-		}`, defaultMethods, test.Header{"Content-Type": "application/json"}, `{"foo": "bar"}`, want{req: test.Header{"x-test": "bar"}}},
+		}`, defaultMethods, test.Header{"Content-Type": "applicAtion/foo+jsOn"}, `{"foo": "bar"}`, want{req: test.Header{"x-test": "bar"}}},
 		{"method /w body", `
 		origin = "` + origin.URL + `"
 		set_request_headers = {
Repository: avenga/couper
Pull request #227 (2021-05-10 09:12:56)

Basic-Auth errors always with 401


Patch:
diff --git a/errors/type_defintions.go b/errors/type_defintions.go
index 6926561c..659e5df2 100644
--- a/errors/type_defintions.go
+++ b/errors/type_defintions.go
@@ -5,7 +5,7 @@ import "net/http"
 // Definitions holds all implemented ones. The name must match the structs
 // snake-name for fallback purposes. See TypeToSnake usage and reference.
 var Definitions = []*Error{
-	AccessControl.Kind("basic_auth"),
+	AccessControl.Kind("basic_auth").Status(http.StatusUnauthorized),
 	AccessControl.Kind("basic_auth").Kind("basic_auth_credentials_missing").Status(http.StatusUnauthorized),
 
 	AccessControl.Kind("jwt"),


Test patch:
diff --git a/handler/access_control_test.go b/handler/access_control_test.go
index d30be836..806d7f4f 100644
--- a/handler/access_control_test.go
+++ b/handler/access_control_test.go
@@ -64,7 +64,7 @@ func TestAccessControl_ServeHTTP(t *testing.T) {
 
 		{"basic_auth", fields{ac.List{ac.NewItem("", newBasicAuth("hans", "word"), defaultErrHandler)}, http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
 			rw.WriteHeader(http.StatusNoContent)
-		})}, newReq("GET", "http://ac.test/")("Authorization", "Basic aGFuczovVnFoV3FsS1VrSVNzUC8K"), http.StatusForbidden},
+		})}, newReq("GET", "http://ac.test/")("Authorization", "Basic aGFuczovVnFoV3FsS1VrSVNzUC8K"), http.StatusUnauthorized},
 
 		{"basic_auth /wo authorization header", fields{ac.List{ac.NewItem("", newBasicAuth("hans", "word"), defaultErrHandler)}, http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
 			rw.WriteHeader(http.StatusNoContent)
@@ -72,7 +72,7 @@ func TestAccessControl_ServeHTTP(t *testing.T) {
 
 		{"basic_auth /w realm", fields{ac.List{ac.NewItem("", newBasicAuth("hans", "word"), defaultErrHandler)}, http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
 			rw.WriteHeader(http.StatusNoContent)
-		})}, newReq("GET", "http://ac.test/")("Authorization", "Basic aGFuczovVnFoV3FsS1VrSVNzUC8K"), http.StatusForbidden},
+		})}, newReq("GET", "http://ac.test/")("Authorization", "Basic aGFuczovVnFoV3FsS1VrSVNzUC8K"), http.StatusUnauthorized},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
Repository: avenga/couper
Pull request #432 (2022-02-01 13:21:13)

empty error_handler labels
Fix and complete error message for empty error_handler labels

---
<details>
    <summary>Reviewer checklist</summary>
    <ul>
        <li>Read PR description: a summary about the changes is required</li>
        <li>Changelog updated</li>
        <li>Documentation: docs/{Reference, Cli, ...}, Docker and cli help/usage</li>
        <li>Pulled branch, manually tested</li>
        <li>Verified requirements are met</li>
        <li>Reviewed the code</li>
        <li>Reviewed the related tests</li>
    </ul>
</details>



Patch:
diff --git a/config/configload/error_handler.go b/config/configload/error_handler.go
index d4722a94..5a42aac0 100644
--- a/config/configload/error_handler.go
+++ b/config/configload/error_handler.go
@@ -70,7 +70,7 @@ func newErrorHandlerContent(content *hcl.BodyContent) (errorHandlerContent, erro
 	}
 
 	for _, block := range content.Blocks.OfType(errorHandler) {
-		kinds, err := newKindsFromLabels(block.Labels)
+		kinds, err := newKindsFromLabels(block)
 		if err != nil {
 			return nil, err
 		}
@@ -107,13 +107,18 @@ func newErrorHandlerContent(content *hcl.BodyContent) (errorHandlerContent, erro
 }
 
 // newKindsFromLabels reads two possible kind formats and returns them per slice entry.
-func newKindsFromLabels(labels []string) ([]string, error) {
+func newKindsFromLabels(block *hcl.Block) ([]string, error) {
 	var allKinds []string
-	for _, kinds := range labels {
+	for _, kinds := range block.Labels {
 		all := strings.Split(kinds, " ")
-		for _, a := range all {
+		for i, a := range all {
 			if a == "" {
-				return nil, errors.Configuration.Messagef("invalid format: %v", labels)
+				err := hcl.Diagnostic{
+					Severity: hcl.DiagError,
+					Summary:  "empty error_handler label",
+					Subject:  &block.LabelRanges[i],
+				}
+				return nil, errors.Configuration.Message(err.Error())
 			}
 		}
 		allKinds = append(allKinds, all...)


Test patch:
diff --git a/config/configload/error_handler_test.go b/config/configload/error_handler_test.go
new file mode 100644
index 00000000..cc515045
--- /dev/null
+++ b/config/configload/error_handler_test.go
@@ -0,0 +1,34 @@
+package configload
+
+import (
+	"fmt"
+	"strings"
+	"testing"
+
+	"github.com/hashicorp/hcl/v2"
+)
+
+func TestErrorHandler_newKindsFromLabels(t *testing.T) {
+	b := &hcl.Block{
+		Labels: []string{""},
+		LabelRanges: []hcl.Range{
+			hcl.Range{
+				Start: hcl.Pos{
+					Line:   123,
+					Column: 321,
+				},
+				End: hcl.Pos{
+					Line:   123,
+					Column: 323,
+				},
+			},
+		},
+	}
+
+	_, err := newKindsFromLabels(b)
+
+	exp := `message:":123,321-323: empty error_handler label; ", synopsis:"configuration error"`
+	if got := fmt.Sprintf("%#v", err); !strings.Contains(got, exp) {
+		t.Errorf("Unexpected error message given: %s", got)
+	}
+}
Repository: okonet/lint-staged
Pull request #881 (2020-06-03 12:13:29)

fix: canceling lint-staged via SIGINT restores state and cleans up
When replacing listr with listr2, this was a change in default behaviour that was left unnoticed

Fixes https://github.com/okonet/lint-staged/issues/880

codecov[bot]: # [Codecov](https://codecov.io/gh/okonet/lint-staged/pull/881?src=pr&el=h1) Report
> Merging [#881](https://codecov.io/gh/okonet/lint-staged/pull/881?src=pr&el=desc) into [master](https://codecov.io/gh/okonet/lint-staged/commit/21a2b411d43158d231b435ae476e379f07e550e1&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/okonet/lint-staged/pull/881/graphs/tree.svg?width=650&height=150&src=pr&token=LSoEgsjk4O)](https://codecov.io/gh/okonet/lint-staged/pull/881?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##            master      #881   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines          597       597           
  Branches       142       142           
=========================================
  Hits           597       597           
```


| [Impacted Files](https://codecov.io/gh/okonet/lint-staged/pull/881?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [lib/runAll.js](https://codecov.io/gh/okonet/lint-staged/pull/881/diff?src=pr&el=tree#diff-bGliL3J1bkFsbC5qcw==) | `100.00% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/okonet/lint-staged/pull/881?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/okonet/lint-staged/pull/881?src=pr&el=footer). Last update [21a2b41...a314047](https://codecov.io/gh/okonet/lint-staged/pull/881?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/lib/runAll.js b/lib/runAll.js
index 4a86d9c..7ad7c56 100644
--- a/lib/runAll.js
+++ b/lib/runAll.js
@@ -119,6 +119,7 @@ const runAll = async (
     ctx,
     exitOnError: false,
     nonTTYRenderer: 'verbose',
+    registerSignalListeners: false,
     ...getRenderer({ debug, quiet }),
   }
 


Test patch:
diff --git a/test/index2.spec.js b/test/index2.spec.js
index 8711aea..7dda8c6 100644
--- a/test/index2.spec.js
+++ b/test/index2.spec.js
@@ -33,6 +33,7 @@ describe('lintStaged', () => {
         },
         "exitOnError": false,
         "nonTTYRenderer": "verbose",
+        "registerSignalListeners": false,
         "renderer": "silent",
       }
     `)
@@ -58,6 +59,7 @@ describe('lintStaged', () => {
         },
         "exitOnError": false,
         "nonTTYRenderer": "verbose",
+        "registerSignalListeners": false,
         "renderer": "verbose",
       }
     `)