X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Fsecurityapi%2Ftypevalidation.go;h=4a9ee28938f3e8d7806e11b59c04be1417455f8d;hb=refs%2Fheads%2Fmaster;hp=90dbda36fde30f8106bee211545c94178311a450;hpb=9e3c79c9e9f3468174a91deb6848e5e386608baf;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/securityapi/typevalidation.go b/capifcore/internal/securityapi/typevalidation.go index 90dbda3..4a9ee28 100644 --- a/capifcore/internal/securityapi/typevalidation.go +++ b/capifcore/internal/securityapi/typevalidation.go @@ -21,6 +21,9 @@ package securityapi import ( + "errors" + "fmt" + "net/url" "strings" ) @@ -35,7 +38,7 @@ func (tokenReq AccessTokenReq) Validate() (bool, AccessTokenErr) { } //3gpp#aefId1:apiName1,apiName2,…apiNameX;aefId2:apiName1,apiName2,…apiNameY;…aefIdN:apiName1,apiName2,…apiNameZ - if tokenReq.Scope != nil { + if tokenReq.Scope != nil && *tokenReq.Scope != "" { scope := strings.Split(*tokenReq.Scope, "#") if len(scope) < 2 { return false, createAccessTokenError(AccessTokenErrErrorInvalidScope, "Malformed scope") @@ -54,6 +57,53 @@ func (tokenReq AccessTokenReq) Validate() (bool, AccessTokenErr) { return true, AccessTokenErr{} } +func (ss ServiceSecurity) Validate() error { + + if len(strings.TrimSpace(string(ss.NotificationDestination))) == 0 { + return errors.New("ServiceSecurity missing required notificationDestination") + } + + if _, err := url.ParseRequestURI(string(ss.NotificationDestination)); err != nil { + return fmt.Errorf("ServiceSecurity has invalid notificationDestination, err=%s", err) + } + + if len(ss.SecurityInfo) == 0 { + return errors.New("ServiceSecurity missing required SecurityInfo") + } + for _, securityInfo := range ss.SecurityInfo { + securityInfo.Validate() + } + return nil +} + +func (si SecurityInformation) Validate() error { + if len(si.PrefSecurityMethods) == 0 { + return errors.New("SecurityInformation missing required PrefSecurityMethods") + } + return nil +} + +func (sn SecurityNotification) Validate() error { + + if len(strings.TrimSpace(string(sn.ApiInvokerId))) == 0 { + return errors.New("SecurityNotification missing required ApiInvokerId") + } + + if len(sn.ApiIds) < 1 { + return errors.New("SecurityNotification missing required ApiIds") + } + + if len(strings.TrimSpace(string(sn.Cause))) == 0 { + return errors.New("SecurityNotification missing required Cause") + } + + if sn.Cause != CauseOVERLIMITUSAGE && sn.Cause != CauseUNEXPECTEDREASON { + return errors.New("SecurityNotification unexpected value for Cause") + } + + return nil +} + func createAccessTokenError(err AccessTokenErrError, message string) AccessTokenErr { return AccessTokenErr{ Error: err,