mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-06 00:01:20 +00:00
Merge pull request #55 from BFNOC/fix-identity-iccid
fix(vowifi): keep the SIM ICCID from start profile to SMS storage
This commit is contained in:
4 files changed
+87
-2
No files matched your search
@@ -73,7 +73,12 @@ func (vowifiDeliveryStore) LoadInboundFragments(
|
||||
}
|
||||
result := make([]messaging.StoredInboundFragment, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
result = append(result, inboundFragmentFromDB(row))
|
||||
// The rows already match the owner's canonical ICCID and IMSI. Hand
|
||||
// the owner back as given so imscore's exact owner check accepts
|
||||
// fragments saved on another device or under a padded ICCID.
|
||||
fragment := inboundFragmentFromDB(row)
|
||||
fragment.Scope.Owner = owner
|
||||
result = append(result, fragment)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package device
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/iniwex5/vowifi-go/runtimehost/messaging"
|
||||
"github.com/yibaiba/hideck/internal/db"
|
||||
)
|
||||
|
||||
func TestLoadInboundFragmentsReturnsRequestedOwner(t *testing.T) {
|
||||
previousDB := db.DB
|
||||
if err := db.Init(filepath.Join(t.TempDir(), "fragments.db")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if sqlDB, err := db.DB.DB(); err == nil {
|
||||
_ = sqlDB.Close()
|
||||
}
|
||||
db.DB = previousDB
|
||||
})
|
||||
|
||||
store := vowifiDeliveryStore{}
|
||||
saved := messaging.InboundFragmentOwner{DeviceID: "dev-a", ICCID: "89640a0000000000001f", IMSI: "530010000000001"}
|
||||
if _, err := store.SaveInboundFragment(
|
||||
messaging.InboundFragmentScope{Owner: saved, SessionKey: "session"},
|
||||
messaging.InboundFragment{Reference: 7, Total: 2, Sequence: 1, Content: "part", ArrivedAt: time.Now()},
|
||||
); err != nil {
|
||||
t.Fatalf("save fragment: %v", err)
|
||||
}
|
||||
|
||||
for _, owner := range []messaging.InboundFragmentOwner{
|
||||
saved,
|
||||
{DeviceID: "dev-b", ICCID: "89640A0000000000001F", IMSI: "530010000000001"},
|
||||
} {
|
||||
records, err := store.LoadInboundFragments(owner)
|
||||
if err != nil {
|
||||
t.Fatalf("load fragments for %+v: %v", owner, err)
|
||||
}
|
||||
if len(records) != 1 || records[0].Scope.Owner != owner {
|
||||
t.Fatalf("load fragments for %+v = %+v", owner, records)
|
||||
}
|
||||
}
|
||||
|
||||
for _, other := range []messaging.InboundFragmentOwner{
|
||||
{DeviceID: "dev-a", ICCID: "8964010000000000002", IMSI: saved.IMSI},
|
||||
{DeviceID: "dev-a", ICCID: saved.ICCID, IMSI: "530010000000002"},
|
||||
} {
|
||||
records, err := store.LoadInboundFragments(other)
|
||||
if err != nil {
|
||||
t.Fatalf("load fragments for %+v: %v", other, err)
|
||||
}
|
||||
if len(records) != 0 {
|
||||
t.Fatalf("another SIM %+v loaded %+v", other, records)
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -99,7 +99,7 @@ func preparedSessionFromInternal(value internalprofile.PreparedSession) Prepared
|
||||
|
||||
func profileFromInternal(value internalprofile.Profile) Profile {
|
||||
return Profile{
|
||||
IMSI: value.IMSI, MCC: value.MCC, MNC: value.MNC, IMEI: value.IMEI,
|
||||
ICCID: value.ICCID, IMSI: value.IMSI, MCC: value.MCC, MNC: value.MNC, IMEI: value.IMEI,
|
||||
UserAgent: value.UserAgent, SMSC: value.SMSC, IMSDomain: value.IMSDomain,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package identity
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPrepareStartKeepsICCID(t *testing.T) {
|
||||
access := &stubAccess{ident: Identity{
|
||||
IMSI: "310280233621715", IMPI: "310280233621715@private.att.net",
|
||||
IMPU: []string{"sip:310280233621715@one.att.net"},
|
||||
Domain: "one.att.net",
|
||||
}}
|
||||
prepared, err := PrepareStart(PrepareStartInput{
|
||||
DeviceID: "wwan0",
|
||||
Profile: Profile{ICCID: " 89012802331234567890 ", IMSI: "310280233621715", MCC: "310", MNC: "280"},
|
||||
Access: access,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("PrepareStart: %v", err)
|
||||
}
|
||||
if prepared.Profile.ICCID != "89012802331234567890" {
|
||||
t.Fatalf("prepared ICCID = %q", prepared.Profile.ICCID)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user