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