| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package vowifi
- import "testing"
- func TestExtractAssociatedMSISDN(t *testing.T) {
- tests := []struct {
- name string
- evidence IMSEvidence
- wantNumber string
- wantSource string
- wantOK bool
- }{
- {
- name: "explicit associated identity with IMS domain",
- evidence: IMSEvidence{
- AssociatedMSISDN: "[email protected]",
- },
- wantNumber: "+447700900123",
- wantSource: PhoneSourceAssociatedMSISDN,
- wantOK: true,
- },
- {
- name: "tel P-Associated-URI",
- evidence: IMSEvidence{
- PAssociatedURI: []string{"<tel:+44 7700-900123>"},
- },
- wantNumber: "+447700900123",
- wantSource: PhoneSourcePAssociatedURI,
- wantOK: true,
- },
- {
- name: "SIP E164 P-Associated-URI",
- evidence: IMSEvidence{
- PAssociatedURI: []string{
- "sip:[email protected]",
- "<sip:[email protected];user=phone>",
- },
- },
- wantNumber: "+447700900123",
- wantSource: PhoneSourcePAssociatedURI,
- wantOK: true,
- },
- {
- name: "percent encoded plus",
- evidence: IMSEvidence{
- PAssociatedURI: []string{"tel:%2B447700900123"},
- },
- wantNumber: "+447700900123",
- wantSource: PhoneSourcePAssociatedURI,
- wantOK: true,
- },
- {
- name: "reject IMSI-shaped SIP IMPU",
- evidence: IMSEvidence{
- PAssociatedURI: []string{
- "sip:[email protected]",
- },
- },
- wantOK: false,
- },
- {
- name: "reject arbitrary untyped P-Associated value",
- evidence: IMSEvidence{
- PAssociatedURI: []string{"+447700900123"},
- },
- wantOK: false,
- },
- {
- name: "reject command characters",
- evidence: IMSEvidence{
- AssociatedMSISDN: "+447700900123;AT+CFUN=0",
- },
- wantOK: false,
- },
- {
- name: "reject overlong E164",
- evidence: IMSEvidence{
- AssociatedMSISDN: "+1234567890123456",
- },
- wantOK: false,
- },
- }
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- number, source, ok := ExtractAssociatedMSISDN(test.evidence)
- if number != test.wantNumber || source != test.wantSource || ok != test.wantOK {
- t.Fatalf(
- "ExtractAssociatedMSISDN() = (%q, %q, %t), want (%q, %q, %t)",
- number,
- source,
- ok,
- test.wantNumber,
- test.wantSource,
- test.wantOK,
- )
- }
- })
- }
- }
- func TestDeriveEPDGUsesExplicitPLMNAndNeverIMSIHeuristics(t *testing.T) {
- tests := []struct {
- name string
- identity SIMIdentity
- want string
- wantErr bool
- }{
- {
- name: "two digit MNC is padded",
- identity: SIMIdentity{
- ICCID: "one",
- IMSI: "untrusted-for-plmn",
- HomeMCC: "234",
- HomeMNC: "15",
- },
- want: "epdg.epc.mnc015.mcc234.pub.3gppnetwork.org",
- },
- {
- name: "three digit MNC is preserved",
- identity: SIMIdentity{
- ICCID: "one",
- HomeMCC: "310",
- HomeMNC: "260",
- },
- want: "epdg.epc.mnc260.mcc310.pub.3gppnetwork.org",
- },
- {
- name: "explicit endpoint",
- identity: SIMIdentity{
- ICCID: "one",
- HomeMCC: "234",
- HomeMNC: "15",
- EPDG: "EPDG.EXAMPLE.NET",
- },
- want: "epdg.example.net",
- },
- {
- name: "missing explicit MNC is not guessed from IMSI",
- identity: SIMIdentity{
- ICCID: "one",
- IMSI: "234150000000000",
- HomeMCC: "234",
- },
- wantErr: true,
- },
- }
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- epdg, err := DeriveEPDG(test.identity)
- if (err != nil) != test.wantErr {
- t.Fatalf("DeriveEPDG() error = %v, wantErr %t", err, test.wantErr)
- }
- if epdg != test.want {
- t.Fatalf("DeriveEPDG() = %q, want %q", epdg, test.want)
- }
- })
- }
- }
|