uranusjr commented on code in PR #69926:
URL: https://github.com/apache/airflow/pull/69926#discussion_r3608512321


##########
go-sdk/pkg/worker/runner_test.go:
##########
@@ -71,6 +75,80 @@ func newTestWorkLoad(id string, dagId string) 
api.ExecuteTaskWorkload {
        }
 }
 
+func TestStartTaskHTTPErrorDoesNotLogToken(t *testing.T) {
+       secretToken := "super-secret-workload-token"
+       type requestDetails struct {
+               authorization string
+               correlationID string
+               method        string
+               path          string
+       }
+       requestReceived := make(chan requestDetails, 1)
+       server := httptest.NewServer(http.HandlerFunc(func(w 
http.ResponseWriter, r *http.Request) {
+               requestReceived <- requestDetails{
+                       authorization: r.Header.Get("Authorization"),
+                       correlationID: r.Header.Get("Correlation-Id"),
+                       method:        r.Method,
+                       path:          r.URL.Path,
+               }
+               w.Header().Set("Content-Type", "application/json")
+               w.WriteHeader(http.StatusBadRequest)
+               if _, err := w.Write([]byte(`{"detail":"simulated start 
failure"}`)); err != nil {
+                       t.Errorf("failed to write test response: %v", err)
+               }
+       }))
+       t.Cleanup(server.Close)
+
+       workload := newTestWorkLoad(uuid.New().String(), "start-error-dag")
+       workload.Token = secretToken
+       workload.LogPath = nil
+       registry := bundlev1.New()
+       registry.AddDag(workload.TI.DagId).AddTaskWithName(workload.TI.TaskId, 
func() error {
+               return nil
+       })
+
+       var logBuffer bytes.Buffer
+       testWorker, err := worker.NewWithBundle(registry, 
slog.New(slog.NewJSONHandler(&logBuffer, nil))).
+               WithServer(server.URL + "/execution/")
+       require.NoError(t, err)
+
+       ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+       defer cancel()
+       err = testWorker.ExecuteTaskWorkload(ctx, workload)
+       require.Error(t, err)
+
+       var request requestDetails
+       select {
+       case request = <-requestReceived:
+       case <-ctx.Done():
+               t.Fatal("start-task request was not received")
+       }
+       require.Equal(t, "Bearer "+secretToken, request.authorization)
+       require.NotEmpty(t, request.correlationID)
+       require.Equal(t, http.MethodPatch, request.method)
+       require.Equal(t, 
"/execution/task-instances/"+workload.TI.Id.String()+"/run", request.path)
+
+       var logEntry map[string]any
+       require.NoError(t, json.Unmarshal(logBuffer.Bytes(), &logEntry))

Review Comment:
   Probably can also do
   
   ```go
   require.NotContains(t, logBuffer.String(), secretToken)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to