nextcloud-spreed-signaling/async_events_nats_test.go
Joachim Bauch f3a81c23c3
Implement custom session id codec that generates shorter ids.
Inspired by the previously used https://github.com/gorilla/securecookie
and simplified / adjusted to our use case.
2025-12-02 16:55:43 +01:00

48 lines
1.5 KiB
Go

/**
* Standalone signaling server for the Nextcloud Spreed app.
* Copyright (C) 2025 struktur AG
*
* @author Joachim Bauch <bauch@struktur.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package signaling
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func Benchmark_GetSubjectForSessionId(b *testing.B) {
require := require.New(b)
backend := &Backend{
id: "compat",
}
data := &SessionIdData{
Sid: 1,
Created: time.Now().UnixMicro(),
BackendId: backend.Id(),
}
codec, err := NewSessionIdCodec([]byte("12345678901234567890123456789012"), []byte("09876543210987654321098765432109"))
require.NoError(err)
sid, err := codec.EncodePublic(data)
require.NoError(err, "could not create session id")
for b.Loop() {
GetSubjectForSessionId(sid, backend)
}
}