Skip to content

Commit 16383da

Browse files
authored
include authmethod and authextra in meta session API (#264)
* include authmethod and authextra in meta session API * potentially fix tests * make sure session count is in sync eventually
1 parent c654a3e commit 16383da

File tree

11 files changed

+46
-20
lines changed

11 files changed

+46
-20
lines changed

acceptor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func Accept(peer Peer, hello *messages.Hello, serializer serializers.Serializer,
157157

158158
Welcomed:
159159
d, _ := a.SessionDetails()
160-
details := NewBaseSession(d.ID(), d.Realm(), d.AuthID(), d.AuthRole(), peer, serializer)
160+
details := NewBaseSession(d.ID(), d.Realm(), d.AuthID(), d.AuthRole(), d.AuthMethod(), d.AuthExtra(), peer, serializer)
161161
return details, nil
162162
}
163163

client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ func ConnectInMemoryBase(router *Router, realm, authID, authRole string,
132132
realm,
133133
authID,
134134
authRole,
135+
"",
136+
map[string]any{},
135137
routerPeer,
136138
serializer,
137139
)
@@ -145,6 +147,8 @@ func ConnectInMemoryBase(router *Router, realm, authID, authRole string,
145147
realm,
146148
authID,
147149
authRole,
150+
"",
151+
map[string]any{},
148152
clientPeer,
149153
serializer,
150154
)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/shirou/gopsutil v3.21.11+incompatible
99
github.com/sirupsen/logrus v1.9.3
1010
github.com/stretchr/testify v1.10.0
11-
github.com/xconnio/wampproto-go v0.0.0-20251103160710-51d26611527b
11+
github.com/xconnio/wampproto-go v0.0.0-20251105154130-632905d8a3d9
1212
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d
1313
gopkg.in/yaml.v3 v3.0.1
1414
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh
4343
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
4444
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
4545
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
46-
github.com/xconnio/wampproto-go v0.0.0-20251103160710-51d26611527b h1:MAJwfVEdTvbfGHbZef1DS+LhJ8rSrzPJ1DxJhfQEDyk=
47-
github.com/xconnio/wampproto-go v0.0.0-20251103160710-51d26611527b/go.mod h1:k2I4x+dOyJq5XW6SHbnwrqJEuRf/lO9rbF5habINuMM=
46+
github.com/xconnio/wampproto-go v0.0.0-20251105154130-632905d8a3d9 h1:2eGfp79Yjj8gf1uNONKVp9FG5U/XhcoAaT1p6kbNJRU=
47+
github.com/xconnio/wampproto-go v0.0.0-20251105154130-632905d8a3d9/go.mod h1:k2I4x+dOyJq5XW6SHbnwrqJEuRf/lO9rbF5habINuMM=
4848
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
4949
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
5050
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=

joiner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ func Join(cl Peer, realm string, serializer serializers.Serializer,
194194
return nil, err
195195
}
196196

197-
base := NewBaseSession(details.ID(), details.Realm(), details.AuthID(), details.AuthRole(), cl, serializer)
197+
base := NewBaseSession(details.ID(), details.Realm(), details.AuthID(), details.AuthRole(),
198+
details.AuthMethod(), details.AuthExtra(), cl, serializer)
198199
return base, nil
199200
}
200201

meta.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ func (m *meta) onJoin(base BaseSession) {
6363
"session": base.ID(),
6464
"authid": base.AuthID(),
6565
"authrole": base.AuthRole(),
66-
"authmethod": "",
66+
"authmethod": base.AuthMethod(),
67+
"authextra": base.AuthExtra(),
6768
"authprovider": "",
6869
}
6970

@@ -263,7 +264,8 @@ func (m *meta) handleSessionGet(_ context.Context, invocation *Invocation) *Invo
263264
"session": client.ID(),
264265
"authid": client.AuthID(),
265266
"authrole": client.AuthRole(),
266-
"authmethod": "",
267+
"authmethod": client.AuthMethod(),
268+
"authextra": client.AuthExtra(),
267269
"authprovider": "",
268270
}
269271
return NewInvocationResult(details)

peer.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,27 @@ const (
2323
RouterOutQueueSizeDefault = 64
2424
)
2525

26-
func NewBaseSession(id uint64, realm, authID, authRole string, cl Peer, serializer serializers.Serializer) BaseSession {
26+
func NewBaseSession(id uint64, realm, authID, authRole, authMethod string, authExtra map[string]any, cl Peer,
27+
serializer serializers.Serializer) BaseSession {
2728
return &baseSession{
2829
id: id,
2930
realm: realm,
3031
authID: authID,
3132
authRole: authRole,
33+
authMethod: authMethod,
34+
authExtra: authExtra,
3235
client: cl,
3336
serializer: serializer,
3437
}
3538
}
3639

3740
type baseSession struct {
38-
id uint64
39-
realm string
40-
authID string
41-
authRole string
41+
id uint64
42+
realm string
43+
authID string
44+
authRole string
45+
authMethod string
46+
authExtra map[string]any
4247

4348
client Peer
4449
serializer serializers.Serializer
@@ -50,6 +55,14 @@ type baseSession struct {
5055
sync.Mutex
5156
}
5257

58+
func (b *baseSession) AuthMethod() string {
59+
return b.authMethod
60+
}
61+
62+
func (b *baseSession) AuthExtra() map[string]any {
63+
return b.authExtra
64+
}
65+
5366
func (b *baseSession) EnableLogPublishing(session *Session, topic string) {
5467
b.Lock()
5568
defer b.Unlock()

realm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (r *Realm) AttachClient(base BaseSession) error {
3232
r.clients.Store(base.ID(), base)
3333

3434
details := wampproto.NewSessionDetails(base.ID(), base.Realm(), base.AuthID(), base.AuthRole(),
35-
base.Serializer().Static(), wampproto.RouterRoles)
35+
base.AuthMethod(), base.Serializer().Static(), wampproto.RouterRoles, base.AuthExtra())
3636

3737
if err := r.broker.AddSession(details); err != nil {
3838
return err

router_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,11 @@ func TestRouterMetaSessionCount(t *testing.T) {
222222
require.NoError(t, session2.Leave())
223223

224224
t.Run("CountAfterAdminSessionLeaves", func(t *testing.T) {
225-
resp := session.Call(xconn.MetaProcedureSessionCount).Do()
226-
require.NoError(t, resp.Err)
227-
require.Equal(t, uint64(2), resp.ArgUInt64Or(0, 0))
225+
require.Eventually(t, func() bool {
226+
resp := session.Call(xconn.MetaProcedureSessionCount).Do()
227+
require.NoError(t, resp.Err)
228+
return uint64(2) == resp.Args()[0]
229+
}, time.Second, 10*time.Millisecond)
228230
})
229231
}
230232

@@ -286,7 +288,7 @@ func TestRouterMetaSessionGet(t *testing.T) {
286288
require.NoError(t, err)
287289

288290
expectedDetails := map[string]any{"authid": session.Details().AuthID(), "authmethod": "", "authprovider": "",
289-
"authrole": "trusted", "session": session.ID()}
291+
"authrole": "trusted", "session": session.ID(), "authextra": map[string]any{}}
290292
resp := session.Call(xconn.MetaProcedureSessionGet).Arg(session.ID()).Do()
291293
require.NoError(t, resp.Err)
292294
require.Equal(t, expectedDetails, resp.Args()[0])

session.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func NewSession(base BaseSession, serializer serializers.Serializer) *Session {
7777

7878
leaveChan: make(chan struct{}, 1),
7979

80-
details: NewSessionDetails(base.ID(), base.Realm(), base.AuthID(), base.AuthRole()),
80+
details: NewSessionDetails(base.ID(), base.Realm(), base.AuthID(), base.AuthRole(), base.AuthMethod(),
81+
base.AuthExtra()),
8182
connected: true,
8283
}
8384

0 commit comments

Comments
 (0)