|
| 1 | +// Copyright 2026 Ella Networks |
| 2 | + |
| 3 | +package ngap_test |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/ellanetworks/core/internal/amf/ngap" |
| 10 | + "github.com/free5gc/ngap/ngapType" |
| 11 | +) |
| 12 | + |
| 13 | +func TestHandlePDUSessionResourceSetupResponse_EmptyIEs(t *testing.T) { |
| 14 | + ran := newTestRadio() |
| 15 | + amfInstance := newTestAMF() |
| 16 | + msg := &ngapType.PDUSessionResourceSetupResponse{} |
| 17 | + |
| 18 | + assertNoPanic(t, "HandlePDUSessionResourceSetupResponse(empty IEs)", func() { |
| 19 | + ngap.HandlePDUSessionResourceSetupResponse(context.Background(), amfInstance, ran, msg) |
| 20 | + }) |
| 21 | +} |
| 22 | + |
| 23 | +// TestHandlePDUSessionResourceSetupResponse_UnknownAMFUENGAPID verifies that a |
| 24 | +// PDUSessionResourceSetupResponse with an AMF_UE_NGAP_ID that doesn't match |
| 25 | +// any existing UE context is handled gracefully — no panic, no further |
| 26 | +// processing. |
| 27 | +// Regression test inspired by open5gs/open5gs#4377. |
| 28 | +func TestHandlePDUSessionResourceSetupResponse_UnknownAMFUENGAPID(t *testing.T) { |
| 29 | + ran := newTestRadio() |
| 30 | + amfInstance := newTestAMF() |
| 31 | + |
| 32 | + msg := &ngapType.PDUSessionResourceSetupResponse{} |
| 33 | + ies := &msg.ProtocolIEs |
| 34 | + |
| 35 | + // AMF UE NGAP ID — bogus value with no matching context |
| 36 | + amfIE := ngapType.PDUSessionResourceSetupResponseIEs{} |
| 37 | + amfIE.Id.Value = ngapType.ProtocolIEIDAMFUENGAPID |
| 38 | + amfIE.Value.Present = ngapType.PDUSessionResourceSetupResponseIEsPresentAMFUENGAPID |
| 39 | + amfIE.Value.AMFUENGAPID = &ngapType.AMFUENGAPID{Value: 1379640380095} |
| 40 | + ies.List = append(ies.List, amfIE) |
| 41 | + |
| 42 | + // RAN UE NGAP ID — bogus value |
| 43 | + ranIE := ngapType.PDUSessionResourceSetupResponseIEs{} |
| 44 | + ranIE.Id.Value = ngapType.ProtocolIEIDRANUENGAPID |
| 45 | + ranIE.Value.Present = ngapType.PDUSessionResourceSetupResponseIEsPresentRANUENGAPID |
| 46 | + ranIE.Value.RANUENGAPID = &ngapType.RANUENGAPID{Value: 99} |
| 47 | + ies.List = append(ies.List, ranIE) |
| 48 | + |
| 49 | + assertNoPanic(t, "HandlePDUSessionResourceSetupResponse(unknown AMF UE NGAP ID)", func() { |
| 50 | + ngap.HandlePDUSessionResourceSetupResponse(context.Background(), amfInstance, ran, msg) |
| 51 | + }) |
| 52 | +} |
| 53 | + |
| 54 | +// TestHandlePDUSessionResourceSetupResponse_NilMessage verifies that passing a |
| 55 | +// nil message does not panic. |
| 56 | +func TestHandlePDUSessionResourceSetupResponse_NilMessage(t *testing.T) { |
| 57 | + ran := newTestRadio() |
| 58 | + amfInstance := newTestAMF() |
| 59 | + |
| 60 | + assertNoPanic(t, "HandlePDUSessionResourceSetupResponse(nil)", func() { |
| 61 | + ngap.HandlePDUSessionResourceSetupResponse(context.Background(), amfInstance, ran, nil) |
| 62 | + }) |
| 63 | +} |
| 64 | + |
| 65 | +// TestHandlePDUSessionResourceSetupResponse_OnlyUnknownRANUENGAPID verifies |
| 66 | +// that when only the RAN_UE_NGAP_ID is present but unknown, the handler does |
| 67 | +// not crash or process further. |
| 68 | +func TestHandlePDUSessionResourceSetupResponse_OnlyUnknownRANUENGAPID(t *testing.T) { |
| 69 | + ran := newTestRadio() |
| 70 | + amfInstance := newTestAMF() |
| 71 | + |
| 72 | + msg := &ngapType.PDUSessionResourceSetupResponse{} |
| 73 | + ies := &msg.ProtocolIEs |
| 74 | + |
| 75 | + ranIE := ngapType.PDUSessionResourceSetupResponseIEs{} |
| 76 | + ranIE.Id.Value = ngapType.ProtocolIEIDRANUENGAPID |
| 77 | + ranIE.Value.Present = ngapType.PDUSessionResourceSetupResponseIEsPresentRANUENGAPID |
| 78 | + ranIE.Value.RANUENGAPID = &ngapType.RANUENGAPID{Value: 42} |
| 79 | + ies.List = append(ies.List, ranIE) |
| 80 | + |
| 81 | + assertNoPanic(t, "HandlePDUSessionResourceSetupResponse(only unknown RAN ID)", func() { |
| 82 | + ngap.HandlePDUSessionResourceSetupResponse(context.Background(), amfInstance, ran, msg) |
| 83 | + }) |
| 84 | +} |
0 commit comments