@@ -6,6 +6,7 @@ package server_test
66import (
77 "bytes"
88 "context"
9+ "encoding/hex"
910 "encoding/json"
1011 "errors"
1112 "io"
@@ -105,25 +106,53 @@ func newV2FakeFactory(tools []vmcp.Tool) *v2FakeMultiSessionFactory {
105106}
106107
107108func (f * v2FakeMultiSessionFactory ) MakeSession (
108- _ context.Context , _ * auth.Identity , _ []* vmcp.Backend ,
109+ _ context.Context , identity * auth.Identity , _ []* vmcp.Backend ,
109110) (vmcpsession.MultiSession , error ) {
110111 if f .err != nil {
111112 return nil , f .err
112113 }
113114 baseSession := transportsession .NewStreamableSession ("auto-id" )
115+
116+ // Populate token hash metadata to match real session factory behavior.
117+ allowAnonymous := vmcpsession .ShouldAllowAnonymous (identity )
118+ if identity != nil && identity .Token != "" && ! allowAnonymous {
119+ testSecret := []byte ("integration-test-secret" )
120+ testSalt := []byte ("test-salt-123456" )
121+ tokenHash := vmcpsession .HashToken (identity .Token , testSecret , testSalt )
122+ baseSession .SetMetadata (vmcpsession .MetadataKeyTokenHash , tokenHash )
123+ baseSession .SetMetadata (vmcpsession .MetadataKeyTokenSalt , hex .EncodeToString (testSalt ))
124+ } else {
125+ baseSession .SetMetadata (vmcpsession .MetadataKeyTokenHash , "" )
126+ }
127+
114128 sess := newV2FakeMultiSession (baseSession , f .tools )
115129 f .lastCreatedSession = sess
116130 return sess , nil
117131}
118132
119133func (f * v2FakeMultiSessionFactory ) MakeSessionWithID (
120- _ context.Context , id string , _ * auth.Identity , _ bool , _ []* vmcp.Backend ,
134+ _ context.Context , id string , identity * auth.Identity , allowAnonymous bool , _ []* vmcp.Backend ,
121135) (vmcpsession.MultiSession , error ) {
122136 f .makeWithIDCalled .Store (true )
123137 if f .err != nil {
124138 return nil , f .err
125139 }
126140 baseSession := transportsession .NewStreamableSession (id )
141+
142+ // Populate token hash metadata to match real session factory behavior.
143+ // This allows integration tests to verify that hashes (not raw tokens) are stored.
144+ if identity != nil && identity .Token != "" && ! allowAnonymous {
145+ // Use a test HMAC secret and salt for integration tests
146+ testSecret := []byte ("integration-test-secret" )
147+ testSalt := []byte ("test-salt-123456" ) // 16 bytes
148+ tokenHash := vmcpsession .HashToken (identity .Token , testSecret , testSalt )
149+ baseSession .SetMetadata (vmcpsession .MetadataKeyTokenHash , tokenHash )
150+ baseSession .SetMetadata (vmcpsession .MetadataKeyTokenSalt , hex .EncodeToString (testSalt ))
151+ } else {
152+ // Anonymous session
153+ baseSession .SetMetadata (vmcpsession .MetadataKeyTokenHash , "" )
154+ }
155+
127156 sess := newV2FakeMultiSession (baseSession , f .tools )
128157 f .lastCreatedSession = sess
129158 return sess , nil
0 commit comments