2020-07-03 17:34:08 +00:00
|
|
|
package home
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2021-05-21 11:55:42 +00:00
|
|
|
"os"
|
2020-07-03 17:34:08 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-03-16 18:00:17 +00:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
2020-07-03 17:34:08 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-03-11 14:32:58 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-07-03 17:34:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAuthGL(t *testing.T) {
|
2021-04-22 11:18:20 +00:00
|
|
|
dir := t.TempDir()
|
2020-07-03 17:34:08 +00:00
|
|
|
|
|
|
|
GLMode = true
|
2021-03-11 14:32:58 +00:00
|
|
|
t.Cleanup(func() {
|
|
|
|
GLMode = false
|
|
|
|
})
|
2020-07-03 17:34:08 +00:00
|
|
|
glFilePrefix = dir + "/gl_token_"
|
|
|
|
|
2021-03-11 14:32:58 +00:00
|
|
|
data := make([]byte, 4)
|
2021-03-16 18:00:17 +00:00
|
|
|
aghos.NativeEndian.PutUint32(data, 1)
|
2021-03-11 14:32:58 +00:00
|
|
|
|
2021-05-21 11:55:42 +00:00
|
|
|
require.Nil(t, os.WriteFile(glFilePrefix+"test", data, 0o644))
|
2020-07-03 17:34:08 +00:00
|
|
|
assert.False(t, glCheckToken("test"))
|
|
|
|
|
|
|
|
data = make([]byte, 4)
|
2021-03-16 18:00:17 +00:00
|
|
|
aghos.NativeEndian.PutUint32(data, uint32(time.Now().UTC().Unix()+60))
|
2021-03-11 14:32:58 +00:00
|
|
|
|
2021-05-21 11:55:42 +00:00
|
|
|
require.Nil(t, os.WriteFile(glFilePrefix+"test", data, 0o644))
|
2021-01-13 14:26:57 +00:00
|
|
|
r, _ := http.NewRequest(http.MethodGet, "http://localhost/", nil)
|
2020-07-03 17:34:08 +00:00
|
|
|
r.AddCookie(&http.Cookie{Name: glCookieName, Value: "test"})
|
|
|
|
assert.True(t, glProcessCookie(r))
|
|
|
|
}
|