mirror of
https://github.com/renorris/openfsd
synced 2026-03-22 14:35:36 +08:00
Changes:
- Implement bootstrapping library for managing several concurrent internal services
- Refactor concurrency model for connections/logical clients and their associated I/O
- Refactor server context singleton
- Refactor error handling
- Most errors are now gracefully sent to the FSD client directly encoded as an $ER packet,
enhancing visibility and debugging
- Most errors are now rightfully treated as non-fatal
- Refactor package/dependency graph
- Refactor calling conventions/interfaces for many packages
- Refactor database package
- Refactor post office
Features:
- Add VATSIM-esque HTTP/JSON "data feed"
- Add ephemeral in-memory database option
- Add user management REST API
- Add improved web interface
- Add MySQL support (drop SQLite support)
86 lines
2.0 KiB
Go
86 lines
2.0 KiB
Go
package protocol
|
|
|
|
import (
|
|
"github.com/go-playground/validator/v10"
|
|
"github.com/stretchr/testify/assert"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestServerIdentificationPDU_Serialize2(t *testing.T) {
|
|
V = validator.New(validator.WithRequiredStructEnabled())
|
|
|
|
tests := []struct {
|
|
name string
|
|
packet string
|
|
want *ServerIdentificationPDU
|
|
wantErr error
|
|
}{
|
|
{
|
|
"Valid",
|
|
"$DISERVER:CLIENT:server server:0123456789abcdef\r\n",
|
|
&ServerIdentificationPDU{
|
|
From: "SERVER",
|
|
To: "CLIENT",
|
|
Version: "server server",
|
|
InitialChallenge: "0123456789abcdef",
|
|
},
|
|
nil,
|
|
},
|
|
{
|
|
"Missing field",
|
|
"$DI:CLIENT:server server:0123456789abcdef\r\n",
|
|
&ServerIdentificationPDU{},
|
|
NewGenericFSDError(SyntaxError, "", "validation error"),
|
|
},
|
|
{
|
|
"Non-hexadecimal challenge",
|
|
"$DISERVER:CLIENT:server server:ghijklmnop\r\n",
|
|
&ServerIdentificationPDU{},
|
|
NewGenericFSDError(SyntaxError, "", "validation error"),
|
|
},
|
|
{
|
|
"Challenge too long",
|
|
"$DISERVER:CLIENT:server server:fd9bb85563fc21920f352a74a0917ea88\r\n",
|
|
&ServerIdentificationPDU{},
|
|
NewGenericFSDError(SyntaxError, "", "validation error"),
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
// Perform the parsing
|
|
pdu := ServerIdentificationPDU{}
|
|
err := pdu.Parse(tc.packet)
|
|
|
|
// Check the error
|
|
if tc.wantErr != nil {
|
|
if strings.Contains(tc.wantErr.Error(), "validation error") {
|
|
assert.Contains(t, err.Error(), "validation error")
|
|
} else {
|
|
assert.EqualError(t, err, tc.wantErr.Error())
|
|
}
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
// Verify the result
|
|
assert.Equal(t, tc.want, &pdu)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestServerIdentificationPDU_Serialize(t *testing.T) {
|
|
{
|
|
pdu := ServerIdentificationPDU{
|
|
From: "SERVER",
|
|
To: "CLIENT",
|
|
Version: "server server",
|
|
InitialChallenge: "12345",
|
|
}
|
|
|
|
s := pdu.Serialize()
|
|
assert.Equal(t, "$DISERVER:CLIENT:server server:12345\r\n", s)
|
|
}
|
|
}
|