mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-15 11:22:49 +03:00
dab0a9d87a
Close #1853 Squashed commit of the following: commit 3730cafabe8fa1dbf2bf75915079d2effe4ff9a3 Merge: 533ae3c26b134469
Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 19:21:08 2020 +0300 Merge remote-tracking branch 'origin/master' into 1853-glinet commit 533ae3c2678cd6cfd26bf9560bee4eb5a015a615 Merge: 3521992b21dfb5ff
Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 19:14:45 2020 +0300 Merge remote-tracking branch 'origin/master' into 1853-glinet commit 3521992b4609fa3400942c89f7a7546dade459bc Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 18:04:53 2020 +0300 logs commit 3e0258782b1a14c08156fe65940ae7b661a42b54 Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 17:11:47 2020 +0300 fix commit bb814db9df1c770d0ea02eafd12bedd122bef894 Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 16:58:37 2020 +0300 minor commit b161bbc5749ce76b16600e0153120935ad20077e Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 16:53:22 2020 +0300 move code commit c506e81265bdee140c0f61255f927c13738efc1a Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Jul 2 10:50:56 2020 +0300 test commit c09f201cbd88498a2328be332197e4d96e5fb115 Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Jul 2 10:42:23 2020 +0300 + "--glinet" command-line argument: Run in GL-Inet compatibility mode
44 lines
994 B
Go
44 lines
994 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, 0644))
|
|
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, 0644))
|
|
r, _ := http.NewRequest("GET", "http://localhost/", nil)
|
|
r.AddCookie(&http.Cookie{Name: glCookieName, Value: "test"})
|
|
assert.True(t, glProcessCookie(r))
|
|
GLMode = false
|
|
}
|