nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: argoproj/argo
Pull request #4496 (2020-11-09 19:52:51)

fix: Ensure redirect to login when using empty auth token
Related to https://github.com/argoproj/argo/pull/4412

Signed-off-by: Simon Behar <simbeh7@gmail.com>

Checklist:

* [ ] My organization is added to [USERS.md](https://github.com/argoproj/argo/blob/master/USERS.md).

<!--

Please leave your PR in draft if you don't need a review yet. 

To fix failing `CI / Codegen`, run `make codegen`. 

-->



Patch:
diff --git a/server/auth/gatekeeper.go b/server/auth/gatekeeper.go
index c59426786..55c135dc7 100644
--- a/server/auth/gatekeeper.go
+++ b/server/auth/gatekeeper.go
@@ -129,9 +129,9 @@ func getAuthHeader(md metadata.MD) string {
 func (s gatekeeper) getClients(ctx context.Context) (versioned.Interface, kubernetes.Interface, *types.Claims, error) {
 	md, _ := metadata.FromIncomingContext(ctx)
 	authorization := getAuthHeader(md)
-	mode, err := s.Modes.GetMode(authorization)
-	if err != nil {
-		return nil, nil, nil, status.Error(codes.InvalidArgument, err.Error())
+	mode, valid := s.Modes.GetMode(authorization)
+	if !valid {
+		return nil, nil, nil, status.Error(codes.Unauthenticated, "token not valid for requested mode")
 	}
 	switch mode {
 	case Client:
diff --git a/server/auth/mode.go b/server/auth/mode.go
index a481ddaf2..7e5e836f4 100644
--- a/server/auth/mode.go
+++ b/server/auth/mode.go
@@ -30,15 +30,12 @@ func (m Modes) Add(value string) error {
 	return nil
 }
 
-func (m Modes) GetMode(authorisation string) (Mode, error) {
-	if strings.HasPrefix(authorisation, sso.Prefix) && m[SSO] {
-		return SSO, nil
+func (m Modes) GetMode(authorisation string) (Mode, bool) {
+	if strings.HasPrefix(authorisation, sso.Prefix) {
+		return SSO, m[SSO]
 	}
-	if (strings.HasPrefix(authorisation, "Bearer ") || strings.HasPrefix(authorisation, "Basic ")) && m[Client] {
-		return Client, nil
+	if strings.HasPrefix(authorisation, "Bearer ") || strings.HasPrefix(authorisation, "Basic ") {
+		return Client, m[Client]
 	}
-	if m[Server] {
-		return Server, nil
-	}
-	return "", errors.New("unrecognized token")
+	return Server, m[Server]
 }


Test patch:
diff --git a/server/auth/mode_test.go b/server/auth/mode_test.go
index 140fc211f..2fe5bd9b6 100644
--- a/server/auth/mode_test.go
+++ b/server/auth/mode_test.go
@@ -43,20 +43,20 @@ func TestModes_GetMode(t *testing.T) {
 		Server: true,
 	}
 	t.Run("Client", func(t *testing.T) {
-		mode, err := m.GetMode("Bearer ")
-		if assert.NoError(t, err) {
+		mode, valid := m.GetMode("Bearer ")
+		if assert.True(t, valid) {
 			assert.Equal(t, Client, mode)
 		}
 	})
 	t.Run("Server", func(t *testing.T) {
-		mode, err := m.GetMode("")
-		if assert.NoError(t, err) {
+		mode, valid := m.GetMode("")
+		if assert.True(t, valid) {
 			assert.Equal(t, Server, mode)
 		}
 	})
 	t.Run("SSO", func(t *testing.T) {
-		mode, err := m.GetMode("Bearer v2:")
-		if assert.NoError(t, err) {
+		mode, valid := m.GetMode("Bearer v2:")
+		if assert.True(t, valid) {
 			assert.Equal(t, SSO, mode)
 		}
 	})
Repository: argoproj/argo
Pull request #4625 (2020-12-02 15:36:41)

fix: Fix TestCleanFieldsExclude
Signed-off-by: Simon Behar <simbeh7@gmail.com>

Checklist:

* [ ] My organization is added to [USERS.md](https://github.com/argoproj/argo/blob/master/USERS.md).

<!--

Please leave your PR in draft if you don't need a review yet. 

To fix failing `CI / Codegen`, run `make codegen`. 

-->



Patch:
diff --git a/util/fields/fields.go b/util/fields/fields.go
index e9ad89c1c..edfd9057d 100644
--- a/util/fields/fields.go
+++ b/util/fields/fields.go
@@ -2,7 +2,6 @@ package fields
 
 import (
 	"encoding/json"
-	"fmt"
 	"strings"
 )
 
@@ -24,10 +23,7 @@ func CleanFields(fieldsQuery string, dataBytes []byte) ([]byte, error) {
 	if err != nil {
 		return nil, err
 	}
-	err = processItem([]string{}, data, exclude, fields)
-	if err != nil {
-		return nil, err
-	}
+	processItem([]string{}, data, exclude, fields)
 	clean, err := json.Marshal(data)
 	if err != nil {
 		return nil, err
@@ -35,7 +31,7 @@ func CleanFields(fieldsQuery string, dataBytes []byte) ([]byte, error) {
 	return clean, nil
 }
 
-func processItem(path []string, item interface{}, exclude bool, fields map[string]interface{}) error {
+func processItem(path []string, item interface{}, exclude bool, fields map[string]interface{}) {
 	if mapItem, ok := item.(map[string]interface{}); ok {
 		for k, v := range mapItem {
 
@@ -53,22 +49,15 @@ func processItem(path []string, item interface{}, exclude bool, fields map[strin
 
 			if exclude && !pathIn || !exclude && parentPathIn {
 				if !pathIn {
-					if err := processItem(append(path, k), v, exclude, fields); err != nil {
-						return err
-					}
+					processItem(append(path, k), v, exclude, fields)
 				}
 			} else {
 				delete(mapItem, k)
 			}
 		}
-		return nil
 	} else if arrayItem, ok := item.([]interface{}); ok {
 		for i := range arrayItem {
-			if err := processItem(path, arrayItem[i], exclude, fields); err != nil {
-				return err
-			}
+			processItem(path, arrayItem[i], exclude, fields)
 		}
-		return nil
 	}
-	return fmt.Errorf("cannot process item for fields, unknown format")
 }


Test patch:
diff --git a/util/fields/fields_test.go b/util/fields/fields_test.go
index 06ac8cb77..d10d2834e 100644
--- a/util/fields/fields_test.go
+++ b/util/fields/fields_test.go
@@ -89,9 +89,9 @@ func TestCleanFieldsExclude(t *testing.T) {
 	err = json.Unmarshal(cleanJsonWf, &cleanWf)
 	assert.NoError(t, err)
 
-	assert.Nil(t, string(cleanWf.Status.Phase))
-	assert.Nil(t, cleanWf.Spec.Entrypoint)
-	assert.Nil(t, cleanWf.Name)
+	assert.Empty(t, string(cleanWf.Status.Phase))
+	assert.Empty(t, cleanWf.Spec.Entrypoint)
+	assert.Empty(t, cleanWf.Name)
 
 	assert.NotNil(t, cleanWf.Status.Nodes)
 }
Repository: argoproj/argo
Pull request #3504 (2020-07-17 15:52:16)

fix: Panic on releaseAllWorkflowLocks if Object is not Unstructured type
Checklist:

* [ ] Either (a) I've created an [enhancement proposal](https://github.com/argoproj/argo/issues/new/choose) and discussed it with the community, (b) this is a bug fix, or (c) this is a chore.
* [ ] The title of the PR is (a) [conventional](https://www.conventionalcommits.org/en/v1.0.0/), (b) states what changed, and (c) suffixes the related issues number. E.g. `"fix(controller): Updates such and such. Fixes #1234"`.  #3503 
* [ ] I've signed the CLA.
* [ ] I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
* [ ] My builds are green. Try syncing with master if they are not. 
* [ ] My organization is added to [USERS.md](https://github.com/argoproj/argo/blob/master/USERS.md).



Patch:
diff --git a/workflow/controller/controller.go b/workflow/controller/controller.go
index 1a24d9084..f4005281f 100644
--- a/workflow/controller/controller.go
+++ b/workflow/controller/controller.go
@@ -838,12 +838,16 @@ func (wfc *WorkflowController) releaseAllWorkflowLocks(obj interface{}) {
 	un, ok := obj.(*unstructured.Unstructured)
 	if !ok {
 		log.Warnf("Key '%s' in index is not an unstructured", obj)
+		return
 	}
 	wf, err := util.FromUnstructured(un)
 	if err != nil {
 		log.Warnf("Invalid workflow object: %v", obj)
+		return
+	}
+	if wf.Status.Synchronization != nil {
+		wfc.syncManager.ReleaseAll(wf)
 	}
-	wfc.syncManager.ReleaseAll(wf)
 }
 
 func (wfc *WorkflowController) isArchivable(wf *wfv1.Workflow) bool {


Test patch:
diff --git a/workflow/controller/controller_test.go b/workflow/controller/controller_test.go
index 03cb025cc..53f546c39 100644
--- a/workflow/controller/controller_test.go
+++ b/workflow/controller/controller_test.go
@@ -5,6 +5,7 @@ import (
 	"testing"
 	"time"
 
+	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
 	"k8s.io/apimachinery/pkg/labels"
 	"k8s.io/client-go/tools/record"
 
@@ -424,3 +425,19 @@ func TestIsArchivable(t *testing.T) {
 		assert.True(t, controller.isArchivable(workflow))
 	})
 }
+
+func TestReleaseAllWorkflowLocks(t *testing.T) {
+	cancel, controller := newController()
+	defer cancel()
+	t.Run("nilObject", func(t *testing.T) {
+		controller.releaseAllWorkflowLocks(nil)
+	})
+	t.Run("unStructuredObject", func(t *testing.T) {
+		un := &unstructured.Unstructured{}
+		controller.releaseAllWorkflowLocks(un)
+	})
+	t.Run("otherObject", func(t *testing.T) {
+		un := &wfv1.Workflow{}
+		controller.releaseAllWorkflowLocks(un)
+	})
+}
Repository: aerokube/selenoid
Pull request #1123 (2021-07-22 10:40:44)

Propagate Content-Type header if client sends it
Some webdrivers check Content-Type header (specifically on create session). Selenium client sends it, we just need to propagate it to the target container.


Patch:
diff --git a/selenoid.go b/selenoid.go
index 5016bb5..5a1ba33 100644
--- a/selenoid.go
+++ b/selenoid.go
@@ -206,6 +206,10 @@ func create(w http.ResponseWriter, r *http.Request) {
 		r.URL.Host, r.URL.Path = u.Host, path.Join(u.Path, r.URL.Path)
 		newBody := removeSelenoidOptions(body)
 		req, _ := http.NewRequest(http.MethodPost, r.URL.String(), bytes.NewReader(newBody))
+		contentType := r.Header.Get("Content-Type")
+		if len(contentType) > 0 {
+			req.Header.Set("Content-Type", contentType)
+		}
 		ctx, done := context.WithTimeout(r.Context(), newSessionAttemptTimeout)
 		defer done()
 		log.Printf("[%d] [SESSION_ATTEMPTED] [%s] [%d]", requestId, u.String(), i)


Test patch:
diff --git a/selenoid_test.go b/selenoid_test.go
index 057c220..c9172df 100644
--- a/selenoid_test.go
+++ b/selenoid_test.go
@@ -304,6 +304,30 @@ func TestSessionCreatedWdHub(t *testing.T) {
 	queue.Release()
 }
 
+func TestSessionWithContentTypeCreatedWdHub(t *testing.T) {
+	root := http.NewServeMux()
+	root.Handle("/wd/hub/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		r.URL.Path = strings.TrimPrefix(r.URL.Path, "/wd/hub")
+		AssertThat(t, r.Header.Get("Content-Type"), Is{"application/json; charset=utf-8"})
+		Selenium().ServeHTTP(w, r)
+	}))
+	manager = &HTTPTest{Handler: root}
+
+	resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "application/json; charset=utf-8", bytes.NewReader([]byte("{}")))
+	AssertThat(t, err, Is{nil})
+	var sess map[string]string
+	AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}})
+
+	resp, err = http.Get(With(srv.URL).Path("/status"))
+	AssertThat(t, err, Is{nil})
+	var state config.State
+	AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}})
+	AssertThat(t, state.Used, EqualTo{1})
+	AssertThat(t, queue.Used(), EqualTo{1})
+	sessions.Remove(sess["sessionId"])
+	queue.Release()
+}
+
 func TestSessionFailedAfterTimeout(t *testing.T) {
 	newSessionAttemptTimeout = 10 * time.Millisecond
 	manager = &HTTPTest{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {