AdGuardHome/internal/home/authglinet_test.go
Ainar Garipov b23ea0a690 Pull request 1816: 5704-rm-endian
Updates #5704.

Squashed commit of the following:

commit 927faf8c3ae0a5deea651ea4249a90ffc80a21c9
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Apr 11 20:02:52 2023 +0300

    all: rm our copy of endian
2023-04-11 20:07:39 +03:00

34 lines
809 B
Go

package home
import (
"net/http"
"os"
"testing"
"time"
"github.com/josharian/native"
"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)
native.Endian.PutUint32(data, 1)
require.NoError(t, os.WriteFile(glFilePrefix+"test", data, 0o644))
assert.False(t, glCheckToken("test"))
data = make([]byte, 4)
native.Endian.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))
}