2020-07-03 18:34:08 +01:00
|
|
|
package home
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2021-05-21 12:55:42 +01:00
|
|
|
"os"
|
2020-07-03 18:34:08 +01:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-03-16 18:00:17 +00:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
2020-07-03 18:34:08 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-03-11 14:32:58 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-07-03 18:34:08 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAuthGL(t *testing.T) {
|
2021-04-22 12:18:20 +01:00
|
|
|
dir := t.TempDir()
|
2020-07-03 18:34:08 +01:00
|
|
|
|
|
|
|
GLMode = true
|
2021-10-22 09:58:18 +01:00
|
|
|
t.Cleanup(func() { GLMode = false })
|
2020-07-03 18:34:08 +01: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-10-22 09:58:18 +01:00
|
|
|
require.NoError(t, os.WriteFile(glFilePrefix+"test", data, 0o644))
|
2020-07-03 18:34:08 +01: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-10-22 09:58:18 +01:00
|
|
|
require.NoError(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 18:34:08 +01:00
|
|
|
r.AddCookie(&http.Cookie{Name: glCookieName, Value: "test"})
|
|
|
|
assert.True(t, glProcessCookie(r))
|
|
|
|
}
|