okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
2f6697a
main
1// Authentication recovery must retry the captured flow and secret fields. 2// A controlled peer changes discovery between attempts to expose rebinding. 3package daemon 4 5import ( 6"encoding/json" 7"io" 8"net/http" 9"testing" 10) 11 12func TestLoginRetryFreezesAdvertisedFlowAndSecretFields (t * testing.T ) { 13values := map [string ]json.RawMessage {"tenant" :json .RawMessage (`"original"` ),"secret" :json .RawMessage (`"one-time-secret"` )} 14var admitted []string 15conn := controlledConnection (t ,func (w http.ResponseWriter ,r * http.Request ) { 16if r .URL .Path != "/auth/logins/chosen-login" { 17t .Errorf ("changed login identity: %s" ,r .URL ) 18 } 19if r .Method == http .MethodGet { 20w .WriteHeader (404 ) 21_ ,_ = io .WriteString (w ,`{"type":"about:blank","title":"Not found","status":404,"code":"not_found","detail":"No retained login"}` ) 22return 23 } 24if r .Method != http .MethodPut { 25t .Errorf ("wrong login admission method %s" ,r .Method ) 26 } 27body ,_ := io .ReadAll (r .Body ) 28admitted = append (admitted ,string (body )) 29if len (admitted )== 1 { 30values ["secret" ]= json .RawMessage (`"edited-after-send"` ) 31delete (values ,"tenant" ) 32w .WriteHeader (201 ) 33_ ,_ = io .WriteString (w ,`{"invalid":"acknowledgment"}` ) 34return 35 } 36w .Header ().Set ("ETag" ,`"login-a"` ) 37_ = json .NewEncoder (w ).Encode (map [string ]any {"id" :"chosen-login" ,"provider" :"provider" ,"url" :"https://provider.example/authorize" ,"expires_at" :"2026-10-04T00:00:00Z" ,"state" :"waiting" ,"instructions" :nil ,"progress" :"Waiting" ,"accounts" : []any {},"failure" :nil }) 38 }) 39result ,err := StartSignInWithID (t .Context (),conn ,"chosen-login" ,"provider" ,"device" ,values ) 40if err != nil || result .ETag != `"login-a"` || len (admitted )!= 2 || admitted [0 ]!= admitted [1 ] { 41t .Fatalf ("login intent changed across retry: %v %#v %v" ,err ,result ,admitted ) 42 } 43var request map [string ]any 44_ = json .Unmarshal ([]byte (admitted [0 ]),& request ) 45if request ["flow" ]!= "device" || request ["values" ].(map [string ]any )["secret" ]!= "one-time-secret" { 46t .Fatalf ("advertised flow or secret omitted: %v" ,request ) 47 } 48} 49 50// The daemon cannot manufacture an invalid extension schema or result. This 51// controlled peer verifies the effect is never replayed and omitted form values 52// do not become unintended null writes.