mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-06 06:10:54 +00:00
Move TSetup to top of file, use in TestSealRequest
This commit is contained in:
parent
4509a4245f
commit
ddc5e02cd7
2 changed files with 54 additions and 66 deletions
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSealRequest(t *testing.T) {
|
func TestSealRequest(t *testing.T) {
|
||||||
SetupRandomKeys(t)
|
TSetup(0, nil)
|
||||||
|
|
||||||
values := url.Values{
|
values := url.Values{
|
||||||
"QuickBrownFox": []string{"LazyDog"},
|
"QuickBrownFox": []string{"LazyDog"},
|
||||||
|
@ -28,3 +28,7 @@ func TestSealRequest(t *testing.T) {
|
||||||
t.Errorf("Failed to round-trip, got back %v", unsealedValues)
|
t.Errorf("Failed to round-trip, got back %v", unsealedValues)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSendRemoteCommand(t *testing.T) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"golang.org/x/crypto/nacl/box"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -15,18 +13,57 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetupRandomKeys(t testing.TB) {
|
const (
|
||||||
_, senderPrivate, err := box.GenerateKey(rand.Reader)
|
SetupWantSocketServer = 1 << iota
|
||||||
if err != nil {
|
SetupWantBackendServer
|
||||||
t.Fatal(err)
|
SetupWantURLs
|
||||||
}
|
)
|
||||||
receiverPublic, _, err := box.GenerateKey(rand.Reader)
|
|
||||||
if err != nil {
|
func TSetup(flags int, backendChecker *TBackendRequestChecker) (socketserver *httptest.Server, backend *httptest.Server, urls TURLs) {
|
||||||
t.Fatal(err)
|
DumpBacklogData()
|
||||||
|
|
||||||
|
ioutil.WriteFile("index.html", []byte(`
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<title>CatBag</title>
|
||||||
|
<link rel="stylesheet" href="//cdn.frankerfacez.com/script/catbag.css">
|
||||||
|
<div id="container">
|
||||||
|
<div id="zf0"></div><div id="zf1"></div><div id="zf2"></div>
|
||||||
|
<div id="zf3"></div><div id="zf4"></div><div id="zf5"></div>
|
||||||
|
<div id="zf6"></div><div id="zf7"></div><div id="zf8"></div>
|
||||||
|
<div id="zf9"></div><div id="catbag"></div>
|
||||||
|
<div id="bottom">
|
||||||
|
A <a href="http://www.frankerfacez.com/">FrankerFaceZ</a> Service
|
||||||
|
— CatBag by <a href="http://www.twitch.tv/wolsk">Wolsk</a>
|
||||||
|
</div>
|
||||||
|
</div>`), 0600)
|
||||||
|
|
||||||
|
conf := &ConfigFile{
|
||||||
|
ServerID: 20,
|
||||||
|
UseSSL: false,
|
||||||
|
OurPublicKey: []byte{176, 149, 72, 209, 35, 42, 110, 220, 22, 236, 212, 129, 213, 199, 1, 227, 185, 167, 150, 159, 117, 202, 164, 100, 9, 107, 45, 141, 122, 221, 155, 73},
|
||||||
|
OurPrivateKey: []byte{247, 133, 147, 194, 70, 240, 211, 216, 223, 16, 241, 253, 120, 14, 198, 74, 237, 180, 89, 33, 146, 146, 140, 58, 88, 160, 2, 246, 112, 35, 239, 87},
|
||||||
|
BackendPublicKey: []byte{19, 163, 37, 157, 50, 139, 193, 85, 229, 47, 166, 21, 153, 231, 31, 133, 41, 158, 8, 53, 73, 0, 113, 91, 13, 181, 131, 248, 176, 18, 1, 107},
|
||||||
}
|
}
|
||||||
|
|
||||||
box.Precompute(&backendSharedKey, receiverPublic, senderPrivate)
|
if flags&SetupWantBackendServer != 0 {
|
||||||
messageBufferPool.New = New4KByteBuffer
|
backend = httptest.NewServer(backendChecker)
|
||||||
|
conf.BackendURL = fmt.Sprintf("http://%s", backend.Listener.Addr().String())
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration = conf
|
||||||
|
setupBackend(conf)
|
||||||
|
|
||||||
|
if flags&SetupWantSocketServer != 0 {
|
||||||
|
serveMux := http.NewServeMux()
|
||||||
|
SetupServerAndHandle(conf, serveMux)
|
||||||
|
|
||||||
|
socketserver = httptest.NewServer(serveMux)
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags&SetupWantURLs != 0 {
|
||||||
|
urls = TGetUrls(socketserver, backend)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const MethodIsPost = "POST"
|
const MethodIsPost = "POST"
|
||||||
|
@ -276,56 +313,3 @@ func TGetUrls(socketserver *httptest.Server, backend *httptest.Server) TURLs {
|
||||||
SavePubMsg: fmt.Sprintf("http://%s/cached_pub", addr),
|
SavePubMsg: fmt.Sprintf("http://%s/cached_pub", addr),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
SetupWantSocketServer = 1 << iota
|
|
||||||
SetupWantBackendServer
|
|
||||||
SetupWantURLs
|
|
||||||
)
|
|
||||||
|
|
||||||
func TSetup(flags int, backendChecker *TBackendRequestChecker) (socketserver *httptest.Server, backend *httptest.Server, urls TURLs) {
|
|
||||||
DumpBacklogData()
|
|
||||||
|
|
||||||
ioutil.WriteFile("index.html", []byte(`
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<title>CatBag</title>
|
|
||||||
<link rel="stylesheet" href="//cdn.frankerfacez.com/script/catbag.css">
|
|
||||||
<div id="container">
|
|
||||||
<div id="zf0"></div><div id="zf1"></div><div id="zf2"></div>
|
|
||||||
<div id="zf3"></div><div id="zf4"></div><div id="zf5"></div>
|
|
||||||
<div id="zf6"></div><div id="zf7"></div><div id="zf8"></div>
|
|
||||||
<div id="zf9"></div><div id="catbag"></div>
|
|
||||||
<div id="bottom">
|
|
||||||
A <a href="http://www.frankerfacez.com/">FrankerFaceZ</a> Service
|
|
||||||
— CatBag by <a href="http://www.twitch.tv/wolsk">Wolsk</a>
|
|
||||||
</div>
|
|
||||||
</div>`), 0600)
|
|
||||||
|
|
||||||
conf := &ConfigFile{
|
|
||||||
ServerID: 20,
|
|
||||||
UseSSL: false,
|
|
||||||
OurPublicKey: []byte{176, 149, 72, 209, 35, 42, 110, 220, 22, 236, 212, 129, 213, 199, 1, 227, 185, 167, 150, 159, 117, 202, 164, 100, 9, 107, 45, 141, 122, 221, 155, 73},
|
|
||||||
OurPrivateKey: []byte{247, 133, 147, 194, 70, 240, 211, 216, 223, 16, 241, 253, 120, 14, 198, 74, 237, 180, 89, 33, 146, 146, 140, 58, 88, 160, 2, 246, 112, 35, 239, 87},
|
|
||||||
BackendPublicKey: []byte{19, 163, 37, 157, 50, 139, 193, 85, 229, 47, 166, 21, 153, 231, 31, 133, 41, 158, 8, 53, 73, 0, 113, 91, 13, 181, 131, 248, 176, 18, 1, 107},
|
|
||||||
}
|
|
||||||
|
|
||||||
if flags&SetupWantBackendServer != 0 {
|
|
||||||
backend = httptest.NewServer(backendChecker)
|
|
||||||
conf.BackendURL = fmt.Sprintf("http://%s", backend.Listener.Addr().String())
|
|
||||||
}
|
|
||||||
|
|
||||||
Configuration = conf
|
|
||||||
setupBackend(conf)
|
|
||||||
|
|
||||||
if flags&SetupWantSocketServer != 0 {
|
|
||||||
serveMux := http.NewServeMux()
|
|
||||||
SetupServerAndHandle(conf, serveMux)
|
|
||||||
|
|
||||||
socketserver = httptest.NewServer(serveMux)
|
|
||||||
}
|
|
||||||
|
|
||||||
if flags&SetupWantURLs != 0 {
|
|
||||||
urls = TGetUrls(socketserver, backend)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue