From 80060df10d9722cb74f4a2d1f56f29c74e9cb9ec Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Thu, 1 Aug 2024 07:02:59 +0000 Subject: [PATCH 1/2] fix: allow empty sd in HandleCreateSmPolicyRequest --- go.mod | 1 + internal/sbi/processor/smpolicy.go | 3 ++- internal/util/convert.go | 1 + internal/util/convert_test.go | 40 ++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 internal/util/convert_test.go diff --git a/go.mod b/go.mod index c4a63ba..77a204c 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/free5gc/util v1.0.6 github.com/gin-contrib/cors v1.6.0 github.com/gin-gonic/gin v1.9.1 + github.com/go-playground/assert/v2 v2.2.0 github.com/google/uuid v1.4.0 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 github.com/pkg/errors v0.9.1 diff --git a/internal/sbi/processor/smpolicy.go b/internal/sbi/processor/smpolicy.go index f30cfca..9a2da32 100644 --- a/internal/sbi/processor/smpolicy.go +++ b/internal/sbi/processor/smpolicy.go @@ -36,12 +36,13 @@ func (p *Processor) HandleCreateSmPolicyRequest( queryStrength := 2 // 2: case-insensitive, 3: case-sensitive logger.SmPolicyLog.Tracef("Handle Create SM Policy Request") - if request.Supi == "" || request.SliceInfo == nil || len(request.SliceInfo.Sd) != 6 { + if request.Supi == "" || request.SliceInfo == nil { problemDetail := util.GetProblemDetail("Errorneous/Missing Mandotory IE", util.ERROR_INITIAL_PARAMETERS) logger.SmPolicyLog.Warnln("Errorneous/Missing Mandotory IE", util.ERROR_INITIAL_PARAMETERS) c.JSON(int(problemDetail.Status), problemDetail) return } + logger.ProcLog.Debugf("Request SUPI:[%s], SNSSAI:[%v]", request.Supi, request.SliceInfo) pcfSelf := p.Context() var ue *pcf_context.UeContext diff --git a/internal/util/convert.go b/internal/util/convert.go index c587862..a3b41dd 100644 --- a/internal/util/convert.go +++ b/internal/util/convert.go @@ -44,6 +44,7 @@ var policyTriggerArray = []models.PolicyControlRequestTrigger{ // } // Convert Snssai form models to hexString(sst(2)+sd(6)) +// TODO: In R17 openapi, it's would be replace by openapi.SnssaiModelsToHex func SnssaiModelsToHex(snssai models.Snssai) string { sst := fmt.Sprintf("%02x", snssai.Sst) return sst + snssai.Sd diff --git a/internal/util/convert_test.go b/internal/util/convert_test.go new file mode 100644 index 0000000..bbf9ecd --- /dev/null +++ b/internal/util/convert_test.go @@ -0,0 +1,40 @@ +package util + +import ( + "testing" + + "github.com/go-playground/assert/v2" + + "github.com/free5gc/openapi/models" +) + +func TestSnssaiModelsToHex(t *testing.T) { + tests := []struct { + name string + snssai models.Snssai + expectString string + }{ + { + name: "01010202", + snssai: models.Snssai{ + Sst: 1, + Sd: "010203", + }, + expectString: "01010203", + }, + { + name: "Empty SD", + snssai: models.Snssai{ + Sst: 1, + }, + expectString: "01", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + output := SnssaiModelsToHex(tt.snssai) + assert.Equal(t, tt.expectString, output) + }) + } +} From 13313a2f7e2cbbca309951d3d79954c2968f6b8e Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Thu, 8 Aug 2024 07:03:01 +0000 Subject: [PATCH 2/2] fix: return when gin reply --- internal/sbi/processor/ampolicy.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/sbi/processor/ampolicy.go b/internal/sbi/processor/ampolicy.go index f162a77..546d1b9 100644 --- a/internal/sbi/processor/ampolicy.go +++ b/internal/sbi/processor/ampolicy.go @@ -174,8 +174,10 @@ func (p *Processor) HandlePostPolicies( // TODO: set gin header c.Header("Location", locationHeader) c.JSON(http.StatusCreated, response) + return } else if problemDetails != nil { c.JSON(int(problemDetails.Status), problemDetails) + return } problemDetails = &models.ProblemDetails{