mirror of
https://github.com/CPunch/gopenfusion.git
synced 2025-05-04 17:00:07 +00:00
Compare commits
No commits in common. "d8277ea89c58834df8eaf1b2e6136a4df9668213" and "b02c141000a822ef5ba788b04344e7e8bf07845b" have entirely different histories.
d8277ea89c
...
b02c141000
10
.github/workflows/tests.yaml
vendored
10
.github/workflows/tests.yaml
vendored
@ -1,19 +1,15 @@
|
|||||||
name: unit-tests
|
name: Go
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- cmd/**
|
- ./**.go
|
||||||
- config/**
|
|
||||||
- internal/**
|
|
||||||
- login/**
|
|
||||||
- shard/**
|
|
||||||
- go.mod
|
- go.mod
|
||||||
- go.sum
|
- go.sum
|
||||||
- .github/workflows/tests.yaml
|
- .github/workflows/tests.yaml
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run:
|
tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
@ -15,16 +15,15 @@ type TestPacketData struct {
|
|||||||
C int32
|
C int32
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
// this is the data we expect to get from encoding the above struct with:
|
||||||
testStruct = TestPacketData{
|
//
|
||||||
A: 1,
|
// Encode(TestPacketData{
|
||||||
B: 2,
|
// A: 1,
|
||||||
UTF16Str: "hello world",
|
// B: 2,
|
||||||
C: 3,
|
// UTF16Str: "hello world",
|
||||||
}
|
// C: 3,
|
||||||
|
// })
|
||||||
// this is the data we expect to get from encoding the above struct
|
var testData = [...]byte{
|
||||||
testData = [...]byte{
|
|
||||||
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||||
0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00,
|
0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00,
|
||||||
0x6f, 0x00, 0x20, 0x00, 0x77, 0x00, 0x6f, 0x00,
|
0x6f, 0x00, 0x20, 0x00, 0x77, 0x00, 0x6f, 0x00,
|
||||||
@ -35,77 +34,31 @@ var (
|
|||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is the data we expect to get from EncryptData(testData, []byte(protocol.DEFAULT_KEY))
|
func TestPacketEncodeDecode(t *testing.T) {
|
||||||
encTestData = []byte{
|
buf := &bytes.Buffer{}
|
||||||
0x23, 0x40, 0x72, 0x51, 0x6c, 0x7e, 0x57, 0x6c,
|
|
||||||
0x05, 0x3b, 0x17, 0x51, 0x02, 0x7e, 0x40, 0x23,
|
|
||||||
0x02, 0x40, 0x7e, 0x51, 0x19, 0x52, 0x38, 0x23,
|
|
||||||
0x1f, 0x40, 0x1e, 0x0a, 0x51, 0x7e, 0x57, 0x23,
|
|
||||||
0x6d, 0x40, 0x72, 0x6e, 0x51, 0x7e, 0x57, 0x23,
|
|
||||||
0x23, 0x40, 0x72, 0x51, 0x6e, 0x7e, 0x57, 0x6d,
|
|
||||||
0x6d, 0x57, 0x72, 0x51, 0x6e, 0x7e, 0x40, 0x23,
|
|
||||||
0x6d, 0x40, 0x7e, 0x51, 0x6e, 0x72, 0x57, 0x23,
|
|
||||||
0x6d, 0x40, 0x72, 0x6e, 0x51, 0x7e, 0x57, 0x23,
|
|
||||||
0x6d, 0x40, 0x72, 0x6d, 0x51, 0x7e, 0x57, 0x23,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestPacketEncode(t *testing.T) {
|
|
||||||
buf := bytes.NewBuffer(nil)
|
|
||||||
pkt := protocol.NewPacket(buf)
|
pkt := protocol.NewPacket(buf)
|
||||||
|
|
||||||
if err := pkt.Encode(testStruct); err != nil {
|
if err := pkt.Encode(TestPacketData{
|
||||||
|
A: 1,
|
||||||
|
B: 2,
|
||||||
|
UTF16Str: "hello world",
|
||||||
|
C: 3,
|
||||||
|
}); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(buf.Bytes(), testData[:]) {
|
if !bytes.Equal(buf.Bytes(), testData[:]) {
|
||||||
t.Error("packet data does not match!")
|
t.Error("packet data does not match!")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func TestPacketDecode(t *testing.T) {
|
|
||||||
buf := bytes.NewBuffer(nil)
|
|
||||||
pkt := protocol.NewPacket(buf)
|
|
||||||
buf.Write(testData[:])
|
|
||||||
|
|
||||||
var test TestPacketData
|
var test TestPacketData
|
||||||
if err := pkt.Decode(&test); err != nil {
|
if err := pkt.Decode(&test); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test != testStruct {
|
if test.A != 1 || test.B != 2 || test.C != 3 || test.UTF16Str != "hello world" {
|
||||||
t.Error("packet data does not match!")
|
t.Error("decoded packet data does not match!")
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDataEncrypt(t *testing.T) {
|
|
||||||
buf := make([]byte, len(testData))
|
|
||||||
copy(buf, testData[:])
|
|
||||||
|
|
||||||
protocol.EncryptData(buf, []byte(protocol.DEFAULT_KEY))
|
|
||||||
|
|
||||||
if !bytes.Equal(buf, encTestData) {
|
|
||||||
t.Error("encrypted data does not match!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDataDecrypt(t *testing.T) {
|
|
||||||
buf := make([]byte, len(encTestData))
|
|
||||||
copy(buf, encTestData)
|
|
||||||
|
|
||||||
protocol.DecryptData(buf, []byte(protocol.DEFAULT_KEY))
|
|
||||||
|
|
||||||
if !bytes.Equal(buf, testData[:]) {
|
|
||||||
t.Error("decrypted data does not match!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateNewKey(t *testing.T) {
|
|
||||||
key := protocol.CreateNewKey(123456789, 0x1234567890abcdef, 0x1234567890abcdef)
|
|
||||||
|
|
||||||
if !bytes.Equal(key, []byte{0x0, 0x31, 0xb8, 0xcd, 0xd, 0xc3, 0xad, 0x67}) {
|
|
||||||
t.Error("key does not match!")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user