mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-17 19:08:25 -07:00
4474e9fcf9
Merge in DNS/adguard-home from fix-openapi to master Squashed commit of the following: commit 0e7530472fb566e5cab73d178c8ec16e5ef11dcb Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Jan 13 17:02:06 2021 +0300 all: imp http handlers, imp docs
44 lines
1005 B
Go
44 lines
1005 B
Go
package home
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAuthGL(t *testing.T) {
|
|
dir := prepareTestDir()
|
|
defer func() { _ = os.RemoveAll(dir) }()
|
|
|
|
GLMode = true
|
|
glFilePrefix = dir + "/gl_token_"
|
|
|
|
tval := uint32(1)
|
|
data := make([]byte, 4)
|
|
if archIsLittleEndian() {
|
|
binary.LittleEndian.PutUint32(data, tval)
|
|
} else {
|
|
binary.BigEndian.PutUint32(data, tval)
|
|
}
|
|
assert.Nil(t, ioutil.WriteFile(glFilePrefix+"test", data, 0o644))
|
|
assert.False(t, glCheckToken("test"))
|
|
|
|
tval = uint32(time.Now().UTC().Unix() + 60)
|
|
data = make([]byte, 4)
|
|
if archIsLittleEndian() {
|
|
binary.LittleEndian.PutUint32(data, tval)
|
|
} else {
|
|
binary.BigEndian.PutUint32(data, tval)
|
|
}
|
|
assert.Nil(t, ioutil.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))
|
|
GLMode = false
|
|
}
|