mirror of
https://github.com/argoproj/argo-cd
synced 2026-05-24 09:50:08 +00:00
feat: Add Access-Control-Allow-Origin: * response header to badges (#5395)
Signed-off-by: Markus Hinz <markus.hinz@syncier.com>
This commit is contained in:
parent
564a1221b3
commit
7dfc439086
2 changed files with 8 additions and 0 deletions
|
|
@ -155,6 +155,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
//Ask cache's to not cache the contents in order prevent the badge from becoming stale
|
||||
w.Header().Set("Cache-Control", "private, no-store")
|
||||
|
||||
//Allow badges to be fetched via XHR from frontend applications without running into CORS issues
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte(badge))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ func TestHandlerFeatureIsEnabled(t *testing.T) {
|
|||
handler.ServeHTTP(rr, req)
|
||||
|
||||
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
||||
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
||||
|
||||
response := rr.Body.String()
|
||||
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
||||
|
|
@ -116,6 +117,7 @@ func TestHandlerFeatureProjectIsEnabled(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
handler.ServeHTTP(rr, req)
|
||||
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
||||
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
||||
response := rr.Body.String()
|
||||
assert.Equal(t, toRGBString(tt.healthColor), leftRectColorPattern.FindStringSubmatch(response)[1])
|
||||
assert.Equal(t, toRGBString(tt.statusColor), rightRectColorPattern.FindStringSubmatch(response)[1])
|
||||
|
|
@ -182,6 +184,7 @@ func TestHandlerFeatureIsEnabledRevisionIsEnabled(t *testing.T) {
|
|||
handler.ServeHTTP(rr, req)
|
||||
|
||||
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
||||
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
||||
|
||||
response := rr.Body.String()
|
||||
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
||||
|
|
@ -204,6 +207,7 @@ func TestHandlerRevisionIsEnabledNoOperationState(t *testing.T) {
|
|||
handler.ServeHTTP(rr, req)
|
||||
|
||||
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
||||
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
||||
|
||||
response := rr.Body.String()
|
||||
assert.Equal(t, toRGBString(Green), leftRectColorPattern.FindStringSubmatch(response)[1])
|
||||
|
|
@ -243,6 +247,7 @@ func TestHandlerFeatureIsDisabled(t *testing.T) {
|
|||
handler.ServeHTTP(rr, req)
|
||||
|
||||
assert.Equal(t, "private, no-store", rr.Header().Get("Cache-Control"))
|
||||
assert.Equal(t, "*", rr.Header().Get("Access-Control-Allow-Origin"))
|
||||
|
||||
response := rr.Body.String()
|
||||
assert.Equal(t, toRGBString(Purple), leftRectColorPattern.FindStringSubmatch(response)[1])
|
||||
|
|
|
|||
Loading…
Reference in a new issue