Improve validation for provider management 17/10317/1
authorelinuxhenrik <henrik.b.andersson@est.tech>
Tue, 31 Jan 2023 09:50:37 +0000 (10:50 +0100)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Tue, 31 Jan 2023 09:51:41 +0000 (10:51 +0100)
Issue-ID: NONRTRIC-814
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: If7a10b6c910695acc1e6573981ed0e8873bb5b1a

capifcore/internal/providermanagementapi/typevalidation.go
capifcore/internal/providermanagementapi/typevalidation_test.go

index 1b2e582..c873f30 100644 (file)
@@ -34,12 +34,15 @@ func (ri RegistrationInformation) Validate() error {
 }
 
 func (fd APIProviderFunctionDetails) Validate() error {
+       if len(strings.TrimSpace(string(fd.ApiProvFuncRole))) == 0 {
+               return errors.New("APIProviderFunctionDetails missing required apiProvFuncRole")
+       }
        switch role := fd.ApiProvFuncRole; role {
        case ApiProviderFuncRoleAEF:
        case ApiProviderFuncRoleAPF:
        case ApiProviderFuncRoleAMF:
        default:
-               return errors.New("APIProviderFunctionDetails missing required apiProvFuncRole")
+               return errors.New("APIProviderFunctionDetails has invalid apiProvFuncRole")
        }
 
        return fd.RegInfo.Validate()
index 3980b19..7698aab 100644 (file)
@@ -59,6 +59,14 @@ func TestValidateAPIProviderFunctionDetails(t *testing.T) {
                assert.Contains(t, err.Error(), "apiProvFuncRole")
        }
 
+       var invalidFuncRole ApiProviderFuncRole = "invalid"
+       funcDetailsUnderTest.ApiProvFuncRole = invalidFuncRole
+       err = funcDetailsUnderTest.Validate()
+       if assert.Error(t, err) {
+               assert.Contains(t, err.Error(), "invalid")
+               assert.Contains(t, err.Error(), "apiProvFuncRole")
+       }
+
        funcDetailsUnderTest.ApiProvFuncRole = ApiProviderFuncRoleAEF
        err = funcDetailsUnderTest.Validate()
        if assert.Error(t, err) {