fix: redirect to login upon authentication error (#9134)

This commit is contained in:
Kayla Washburn
2023-08-17 13:54:20 -06:00
committed by GitHub
parent 720ad9a653
commit 9710bada06
4 changed files with 47 additions and 4 deletions

View File

@ -3,11 +3,13 @@ package httpmw_test
import (
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
"time"
@ -197,6 +199,11 @@ func TestAPIKey(t *testing.T) {
res := rw.Result()
defer res.Body.Close()
require.Equal(t, http.StatusUnauthorized, res.StatusCode)
var apiRes codersdk.Response
dec := json.NewDecoder(res.Body)
_ = dec.Decode(&apiRes)
require.True(t, strings.HasPrefix(apiRes.Detail, "API key expired"))
})
t.Run("Valid", func(t *testing.T) {