mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-26 00:28:16 +03:00
ea8950a80d
Squashed commit of the following: commit 5345a14b3565f358c56a37500cafb35b7e397951 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 21 21:13:06 2021 +0300 all: fix windows tests commit 8b9cdbe3e78f43339d21277f04e686bb154f6968 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 21 20:23:55 2021 +0300 all: imp code commit 271fdbe74c29d8ea4b53d7f56d2a36612dfed7b3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 21 19:43:32 2021 +0300 all: imp testing commit e340f9d48679c57fc8eb579b8b78d4957be111c4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 21 18:53:51 2021 +0300 all: use testutil
34 lines
841 B
Go
34 lines
841 B
Go
package home
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAuthGL(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
GLMode = true
|
|
t.Cleanup(func() { GLMode = false })
|
|
glFilePrefix = dir + "/gl_token_"
|
|
|
|
data := make([]byte, 4)
|
|
aghos.NativeEndian.PutUint32(data, 1)
|
|
|
|
require.NoError(t, os.WriteFile(glFilePrefix+"test", data, 0o644))
|
|
assert.False(t, glCheckToken("test"))
|
|
|
|
data = make([]byte, 4)
|
|
aghos.NativeEndian.PutUint32(data, uint32(time.Now().UTC().Unix()+60))
|
|
|
|
require.NoError(t, os.WriteFile(glFilePrefix+"test", data, 0o644))
|
|
r, _ := http.NewRequest(http.MethodGet, "http://localhost/", nil)
|
|
r.AddCookie(&http.Cookie{Name: glCookieName, Value: "test"})
|
|
assert.True(t, glProcessCookie(r))
|
|
}
|