Skip to content

Commit

Permalink
fix: fix fuzzy test
Browse files Browse the repository at this point in the history
  • Loading branch information
donald1218 authored and ianchen0119 committed Apr 25, 2024
1 parent 067f07f commit 3a37c66
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ cscope.*
# Debug
*.log
*.pcap

# R17
openapi
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ require (
github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65E
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk=
github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
Expand Down Expand Up @@ -156,4 +158,4 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
14 changes: 14 additions & 0 deletions internal/nas/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

amf_context "github.com/free5gc/amf/internal/context"
"github.com/free5gc/amf/internal/logger"
amf_nas "github.com/free5gc/amf/internal/nas"
"github.com/free5gc/amf/internal/sbi/consumer"
"github.com/free5gc/amf/pkg/service"
"github.com/free5gc/nas"
"github.com/free5gc/nas/nasMessage"
"github.com/free5gc/nas/nasType"
Expand Down Expand Up @@ -129,6 +132,7 @@ func FuzzHandleNAS2(f *testing.F) {
Tac: "1",
}
amfSelf.SupportTaiLists = []models.Tai{tai}
amfSelf.NrfUri = "test"

msg := nas.NewMessage()
msg.GmmMessage = nas.NewGmmMessage()
Expand Down Expand Up @@ -211,6 +215,16 @@ func FuzzHandleNAS2(f *testing.F) {
f.Add(buf)

f.Fuzz(func(t *testing.T, d []byte) {
ctrl := gomock.NewController(t)
m := service.NewMockApp(ctrl)
service.AMF = m
c, err := consumer.NewConsumer(m)
require.NoError(t, err)
m.EXPECT().
Consumer().
AnyTimes().
Return(c)

ue := new(amf_context.RanUe)
ue.Ran = new(amf_context.AmfRan)
ue.Ran.AnType = models.AccessType__3_GPP_ACCESS
Expand Down
3 changes: 3 additions & 0 deletions internal/sbi/consumer/ausf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func (s *nausfService) SendUEAuthenticationAuthenticateRequest(ue *amf_context.A
resynchronizationInfo *models.ResynchronizationInfo,
) (*models.UeAuthenticationCtx, *models.ProblemDetails, error) {
client := s.getUEAuthenticationClient(ue.AusfUri)
if client == nil {
return nil, nil, openapi.ReportError("ausf not found")
}

amfSelf := amf_context.GetSelf()
servedGuami := amfSelf.ServedGuamiList[0]
Expand Down
15 changes: 13 additions & 2 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ import (
"github.com/free5gc/amf/pkg/factory"
)

var _ App = &AmfApp{}

type App interface {
Start(tlsKeyLogPath string)
Terminate()
Config() *factory.Config
Context() *amf_context.AMFContext
CancelContext() context.Context
Consumer() *consumer.Consumer
}

type AmfApp struct {
cfg *factory.Config
amfCtx *amf_context.AMFContext
Expand All @@ -26,9 +37,9 @@ type AmfApp struct {
stop func(*AmfApp)
}

var AMF *AmfApp
var AMF App

func GetApp() *AmfApp {
func GetApp() App {
return AMF
}

Expand Down
123 changes: 123 additions & 0 deletions pkg/service/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a37c66

Please sign in to comment.