Issue-ID: NONRTRIC-814
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: Ic9f6038faa123325a0c8a8be7a7f5cc5f7a586a0
return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, "invalid format for invoker"))
}
return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, "invalid format for invoker"))
}
- if im.isInvokerOnboarded(newInvoker) {
- return sendCoreError(ctx, http.StatusForbidden, fmt.Sprintf(errMsg, "invoker already onboarded"))
+ if err := im.isInvokerOnboarded(newInvoker); err != nil {
+ return sendCoreError(ctx, http.StatusForbidden, fmt.Sprintf(errMsg, err))
}
if err := im.validateInvoker(newInvoker, ctx); err != nil {
}
if err := im.validateInvoker(newInvoker, ctx); err != nil {
-func (im *InvokerManager) isInvokerOnboarded(newInvoker invokerapi.APIInvokerEnrolmentDetails) bool {
+func (im *InvokerManager) isInvokerOnboarded(newInvoker invokerapi.APIInvokerEnrolmentDetails) error {
for _, invoker := range im.onboardedInvokers {
for _, invoker := range im.onboardedInvokers {
- if invoker.IsOnboarded(newInvoker) {
- return true
+ if err := invoker.ValidateAlreadyOnboarded(newInvoker); err != nil {
+ return err
}
func (im *InvokerManager) prepareNewInvoker(newInvoker *invokerapi.APIInvokerEnrolmentDetails) {
}
func (im *InvokerManager) prepareNewInvoker(newInvoker *invokerapi.APIInvokerEnrolmentDetails) {
-func (ied *APIInvokerEnrolmentDetails) IsOnboarded(otherInvoker APIInvokerEnrolmentDetails) bool {
- return ied.OnboardingInformation.ApiInvokerPublicKey == otherInvoker.OnboardingInformation.ApiInvokerPublicKey
+func (ied *APIInvokerEnrolmentDetails) ValidateAlreadyOnboarded(otherInvoker APIInvokerEnrolmentDetails) error {
+ if ied.OnboardingInformation.ApiInvokerPublicKey == otherInvoker.OnboardingInformation.ApiInvokerPublicKey {
+ return errors.New("invoker with identical public key already onboarded")
+ }
+ return nil
-func TestIsOnboarded(t *testing.T) {
+func TestValidateAlreadyOnboarded(t *testing.T) {
publicKey := "publicKey"
invokerUnderTest := APIInvokerEnrolmentDetails{
OnboardingInformation: OnboardingInformation{
publicKey := "publicKey"
invokerUnderTest := APIInvokerEnrolmentDetails{
OnboardingInformation: OnboardingInformation{
ApiInvokerPublicKey: "otherPublicKey",
},
}
ApiInvokerPublicKey: "otherPublicKey",
},
}
- assert.False(t, invokerUnderTest.IsOnboarded(otherInvoker))
+ assert.Nil(t, invokerUnderTest.ValidateAlreadyOnboarded(otherInvoker))
otherInvoker.OnboardingInformation.ApiInvokerPublicKey = publicKey
otherInvoker.OnboardingInformation.ApiInvokerPublicKey = publicKey
- assert.True(t, invokerUnderTest.IsOnboarded(otherInvoker))
+ assert.NotNil(t, invokerUnderTest.ValidateAlreadyOnboarded(otherInvoker))
return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, "invalid format for provider"))
}
return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, "invalid format for provider"))
}
- if pm.isProviderRegistered(newProvider) {
- return sendCoreError(ctx, http.StatusForbidden, fmt.Sprintf(errMsg, "provider already registered"))
+ if err := pm.isProviderRegistered(newProvider); err != nil {
+ return sendCoreError(ctx, http.StatusForbidden, fmt.Sprintf(errMsg, err))
}
if err := newProvider.Validate(); err != nil {
}
if err := newProvider.Validate(); err != nil {
-func (pm *ProviderManager) isProviderRegistered(newProvider provapi.APIProviderEnrolmentDetails) bool {
+func (pm *ProviderManager) isProviderRegistered(newProvider provapi.APIProviderEnrolmentDetails) error {
for _, prov := range pm.registeredProviders {
for _, prov := range pm.registeredProviders {
- if prov.IsRegistered(newProvider) {
- return true
+ if err := prov.ValidateAlreadyRegistered(newProvider); err != nil {
+ return err
}
func (pm *ProviderManager) prepareNewProvider(newProvider *provapi.APIProviderEnrolmentDetails) {
}
func (pm *ProviderManager) prepareNewProvider(newProvider *provapi.APIProviderEnrolmentDetails) {
-func (pd APIProviderEnrolmentDetails) IsRegistered(otherProvider APIProviderEnrolmentDetails) bool {
- return pd.RegSec == otherProvider.RegSec
+func (pd APIProviderEnrolmentDetails) ValidateAlreadyRegistered(otherProvider APIProviderEnrolmentDetails) error {
+ if pd.RegSec == otherProvider.RegSec {
+ return errors.New("provider with identical regSec already registered")
+ }
+ return nil
assert.Nil(t, providerDetailsUnderTest.Validate())
}
assert.Nil(t, providerDetailsUnderTest.Validate())
}
-func TestIsRegistered(t *testing.T) {
+func TestValidateAlreadyRegistered(t *testing.T) {
regSec := "regSec"
providerUnderTest := APIProviderEnrolmentDetails{
RegSec: regSec,
regSec := "regSec"
providerUnderTest := APIProviderEnrolmentDetails{
RegSec: regSec,
otherProvider := APIProviderEnrolmentDetails{
RegSec: "otherRegSec",
}
otherProvider := APIProviderEnrolmentDetails{
RegSec: "otherRegSec",
}
- assert.False(t, providerUnderTest.IsRegistered(otherProvider))
+ assert.Nil(t, providerUnderTest.ValidateAlreadyRegistered(otherProvider))
otherProvider.RegSec = regSec
otherProvider.RegSec = regSec
- assert.True(t, providerUnderTest.IsRegistered(otherProvider))
+ assert.NotNil(t, providerUnderTest.ValidateAlreadyRegistered(otherProvider))
}
func getProvider() APIProviderEnrolmentDetails {
}
func getProvider() APIProviderEnrolmentDetails {
return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errorMsg, "invalid format for service "+apfId))
}
return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errorMsg, "invalid format for service "+apfId))
}
- if ps.isServicePublished(newServiceAPIDescription) {
- return sendCoreError(ctx, http.StatusForbidden, fmt.Sprintf(errorMsg, "service already published"))
+ if err := ps.isServicePublished(newServiceAPIDescription); err != nil {
+ return sendCoreError(ctx, http.StatusForbidden, fmt.Sprintf(errorMsg, err))
}
if err := newServiceAPIDescription.Validate(); err != nil {
}
if err := newServiceAPIDescription.Validate(); err != nil {
-func (ps *PublishService) isServicePublished(newService publishapi.ServiceAPIDescription) bool {
+func (ps *PublishService) isServicePublished(newService publishapi.ServiceAPIDescription) error {
for _, services := range ps.publishedServices {
for _, service := range services {
for _, services := range ps.publishedServices {
for _, service := range services {
- if service.IsPublished(newService) {
- return true
+ if err := service.ValidateAlreadyPublished(newService); err != nil {
+ return err
}
func (ps *PublishService) installHelmChart(newServiceAPIDescription publishapi.ServiceAPIDescription, ctx echo.Context) (bool, error) {
}
func (ps *PublishService) installHelmChart(newServiceAPIDescription publishapi.ServiceAPIDescription, ctx echo.Context) (bool, error) {
-func (sd ServiceAPIDescription) IsPublished(otherService ServiceAPIDescription) bool {
- return sd.ApiName == otherService.ApiName
+func (sd ServiceAPIDescription) ValidateAlreadyPublished(otherService ServiceAPIDescription) error {
+ if sd.ApiName == otherService.ApiName {
+ return errors.New("service with identical apiName is already published")
+ }
+ return nil
-func TestIsServicePublished(t *testing.T) {
+func TestValidateAlreadyPublished(t *testing.T) {
apiName := "apiName"
serviceUnderTest := ServiceAPIDescription{
ApiName: apiName,
apiName := "apiName"
serviceUnderTest := ServiceAPIDescription{
ApiName: apiName,
otherService := ServiceAPIDescription{
ApiName: "otherApiName",
}
otherService := ServiceAPIDescription{
ApiName: "otherApiName",
}
- assert.False(t, serviceUnderTest.IsPublished(otherService))
+ assert.Nil(t, serviceUnderTest.ValidateAlreadyPublished(otherService))
otherService.ApiName = apiName
otherService.ApiName = apiName
- assert.True(t, serviceUnderTest.IsPublished(otherService))
+ assert.NotNil(t, serviceUnderTest.ValidateAlreadyPublished(otherService))