2 // ========================LICENSE_START=================================
5 // Copyright (C) 2023: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
26 "github.com/stretchr/testify/assert"
27 "oransc.org/nonrtric/capifcore/internal/common29122"
28 publishapi "oransc.org/nonrtric/capifcore/internal/publishserviceapi"
31 func TestPrepareNewSecurityContext(t *testing.T) {
32 apiId := "app-management"
34 description := "Description"
35 services := []publishapi.ServiceAPIDescription{
37 AefProfiles: &[]publishapi.AefProfile{
40 Versions: []publishapi.Version{
42 Resources: &[]publishapi.Resource{
44 CommType: "REQUEST_RESPONSE",
49 SecurityMethods: &[]publishapi.SecurityMethod{
50 publishapi.SecurityMethodPKI,
55 Description: &description,
59 servSecurityUnderTest := ServiceSecurity{
60 NotificationDestination: common29122.Uri("http://golang.cafe/"),
61 SecurityInfo: []SecurityInformation{
63 PrefSecurityMethods: []publishapi.SecurityMethod{
64 publishapi.SecurityMethodOAUTH,
70 err := servSecurityUnderTest.PrepareNewSecurityContext(services)
73 assert.Contains(t, err.Error(), "not found ")
74 assert.Contains(t, err.Error(), "security method")
76 servSecurityUnderTest.SecurityInfo = []SecurityInformation{
80 PrefSecurityMethods: []publishapi.SecurityMethod{
81 publishapi.SecurityMethodOAUTH,
86 servSecurityUnderTest.PrepareNewSecurityContext(services)
87 assert.Equal(t, publishapi.SecurityMethodPKI, *servSecurityUnderTest.SecurityInfo[0].SelSecurityMethod)
89 servSecurityUnderTest.SecurityInfo = []SecurityInformation{
92 PrefSecurityMethods: []publishapi.SecurityMethod{
93 publishapi.SecurityMethodOAUTH,
95 InterfaceDetails: &publishapi.InterfaceDescription{
96 SecurityMethods: &[]publishapi.SecurityMethod{
97 publishapi.SecurityMethodPSK,
103 servSecurityUnderTest.PrepareNewSecurityContext(services)
104 assert.Equal(t, publishapi.SecurityMethodPSK, *servSecurityUnderTest.SecurityInfo[0].SelSecurityMethod)