mirror of
https://github.com/argoproj/argo-cd
synced 2026-05-24 09:50:08 +00:00
* Support OAuth2 login flow from CLI (resolves #172) * Refactor SessionManager to handle local and OAuth2 logins. * argo login will request permanent credentials after OAuth2 flow * Implement proper OIDC app state nonce. Add explicit `--sso` flag to `argo login`
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package webhook
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
appclientset "github.com/argoproj/argo-cd/pkg/client/clientset/versioned/fake"
|
|
"github.com/argoproj/argo-cd/util/settings"
|
|
"github.com/gobuffalo/packr"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var (
|
|
box packr.Box
|
|
)
|
|
|
|
func init() {
|
|
box = packr.NewBox(".")
|
|
}
|
|
|
|
func NewMockHandler() *ArgoCDWebhookHandler {
|
|
appClientset := appclientset.NewSimpleClientset()
|
|
return NewHandler("", appClientset, &settings.ArgoCDSettings{})
|
|
}
|
|
func TestGitHubCommitEvent(t *testing.T) {
|
|
h := NewMockHandler()
|
|
req := httptest.NewRequest("POST", "/api/webhook", nil)
|
|
req.Header.Set("X-GitHub-Event", "push")
|
|
req.Body = ioutil.NopCloser(bytes.NewReader(box.Bytes("github-commit-event.json")))
|
|
w := httptest.NewRecorder()
|
|
h.Handler(w, req)
|
|
assert.Equal(t, w.Code, http.StatusOK)
|
|
}
|
|
|
|
func TestGitHubTagEvent(t *testing.T) {
|
|
h := NewMockHandler()
|
|
req := httptest.NewRequest("POST", "/api/webhook", nil)
|
|
req.Header.Set("X-GitHub-Event", "push")
|
|
req.Body = ioutil.NopCloser(bytes.NewReader(box.Bytes("github-tag-event.json")))
|
|
w := httptest.NewRecorder()
|
|
h.Handler(w, req)
|
|
assert.Equal(t, w.Code, http.StatusOK)
|
|
}
|