1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00

AAKaaS originHash (#4843)

* originHash

* analysis output

* unit tests
This commit is contained in:
tiloKo 2024-03-05 15:21:34 +01:00 committed by GitHub
parent a675ed25e9
commit c0e56d26e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 200 additions and 39 deletions

View File

@ -23,7 +23,7 @@ func runAbapAddonAssemblyKitCheckCVs(config *abapAddonAssemblyKitCheckCVsOptions
log.Entry().Info("╚══════════════════════════════╝")
conn := new(abapbuild.Connector)
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, *utils); err != nil {
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, *utils, ""); err != nil {
return err
}

View File

@ -23,7 +23,7 @@ func runAbapAddonAssemblyKitCheckPV(config *abapAddonAssemblyKitCheckPVOptions,
log.Entry().Info("╚═════════════════════════════╝")
conn := new(abapbuild.Connector)
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, utils); err != nil {
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, utils, ""); err != nil {
return err
}

View File

@ -29,7 +29,7 @@ func abapAddonAssemblyKitCreateTargetVector(config abapAddonAssemblyKitCreateTar
func runAbapAddonAssemblyKitCreateTargetVector(config *abapAddonAssemblyKitCreateTargetVectorOptions, telemetryData *telemetry.CustomData, client piperhttp.Sender, cpe *abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment) error {
conn := new(abapbuild.Connector)
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, client); err != nil {
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, client, config.AbapAddonAssemblyKitOriginHash); err != nil {
return err
}

View File

@ -18,10 +18,11 @@ import (
)
type abapAddonAssemblyKitCreateTargetVectorOptions struct {
AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
AddonDescriptor string `json:"addonDescriptor,omitempty"`
AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
AddonDescriptor string `json:"addonDescriptor,omitempty"`
AbapAddonAssemblyKitOriginHash string `json:"abapAddonAssemblyKitOriginHash,omitempty"`
}
type abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment struct {
@ -90,6 +91,7 @@ For Terminology refer to the [Scenario Description](https://www.project-piper.io
}
log.RegisterSecret(stepConfig.Username)
log.RegisterSecret(stepConfig.Password)
log.RegisterSecret(stepConfig.AbapAddonAssemblyKitOriginHash)
if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 {
sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID)
@ -163,6 +165,7 @@ func addAbapAddonAssemblyKitCreateTargetVectorFlags(cmd *cobra.Command, stepConf
cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for the Addon Assembly Kit as a Service (AAKaaS) system")
cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for the Addon Assembly Kit as a Service (AAKaaS) system")
cmd.Flags().StringVar(&stepConfig.AddonDescriptor, "addonDescriptor", os.Getenv("PIPER_addonDescriptor"), "Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions")
cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitOriginHash, "abapAddonAssemblyKitOriginHash", os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"), "Origin Hash for restricted AAKaaS scenarios")
cmd.MarkFlagRequired("abapAddonAssemblyKitEndpoint")
cmd.MarkFlagRequired("username")
@ -225,6 +228,15 @@ func abapAddonAssemblyKitCreateTargetVectorMetadata() config.StepData {
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_addonDescriptor"),
},
{
Name: "abapAddonAssemblyKitOriginHash",
ResourceRef: []config.ResourceReference{},
Scope: []string{"PARAMETERS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"),
},
},
},
Outputs: config.StepOutputs{

View File

@ -23,7 +23,7 @@ func abapAddonAssemblyKitPublishTargetVector(config abapAddonAssemblyKitPublishT
func runAbapAddonAssemblyKitPublishTargetVector(config *abapAddonAssemblyKitPublishTargetVectorOptions, telemetryData *telemetry.CustomData, utils *aakaas.AakUtils) error {
conn := new(abapbuild.Connector)
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, *utils); err != nil {
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, *utils, config.AbapAddonAssemblyKitOriginHash); err != nil {
return err
}
conn.MaxRuntime = (*utils).GetMaxRuntime()

View File

@ -16,13 +16,14 @@ import (
)
type abapAddonAssemblyKitPublishTargetVectorOptions struct {
AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
TargetVectorScope string `json:"targetVectorScope,omitempty" validate:"possible-values=T P"`
MaxRuntimeInMinutes int `json:"maxRuntimeInMinutes,omitempty"`
PollingIntervalInSeconds int `json:"pollingIntervalInSeconds,omitempty"`
AddonDescriptor string `json:"addonDescriptor,omitempty"`
AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
TargetVectorScope string `json:"targetVectorScope,omitempty" validate:"possible-values=T P"`
MaxRuntimeInMinutes int `json:"maxRuntimeInMinutes,omitempty"`
PollingIntervalInSeconds int `json:"pollingIntervalInSeconds,omitempty"`
AddonDescriptor string `json:"addonDescriptor,omitempty"`
AbapAddonAssemblyKitOriginHash string `json:"abapAddonAssemblyKitOriginHash,omitempty"`
}
// AbapAddonAssemblyKitPublishTargetVectorCommand This step triggers the publication of the Target Vector according to the specified scope.
@ -61,6 +62,7 @@ For Terminology refer to the [Scenario Description](https://www.project-piper.io
}
log.RegisterSecret(stepConfig.Username)
log.RegisterSecret(stepConfig.Password)
log.RegisterSecret(stepConfig.AbapAddonAssemblyKitOriginHash)
if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 {
sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID)
@ -136,6 +138,7 @@ func addAbapAddonAssemblyKitPublishTargetVectorFlags(cmd *cobra.Command, stepCon
cmd.Flags().IntVar(&stepConfig.MaxRuntimeInMinutes, "maxRuntimeInMinutes", 16, "Maximum runtime for status polling in minutes")
cmd.Flags().IntVar(&stepConfig.PollingIntervalInSeconds, "pollingIntervalInSeconds", 60, "Wait time in seconds between polling calls")
cmd.Flags().StringVar(&stepConfig.AddonDescriptor, "addonDescriptor", os.Getenv("PIPER_addonDescriptor"), "Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions")
cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitOriginHash, "abapAddonAssemblyKitOriginHash", os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"), "Origin Hash for restricted AAKaaS scenarios")
cmd.MarkFlagRequired("abapAddonAssemblyKitEndpoint")
cmd.MarkFlagRequired("username")
@ -225,6 +228,15 @@ func abapAddonAssemblyKitPublishTargetVectorMetadata() config.StepData {
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_addonDescriptor"),
},
{
Name: "abapAddonAssemblyKitOriginHash",
ResourceRef: []config.ResourceReference{},
Scope: []string{"PARAMETERS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"),
},
},
},
},

View File

@ -40,7 +40,7 @@ func runAbapAddonAssemblyKitRegisterPackages(config *abapAddonAssemblyKitRegiste
}
conn := new(abapbuild.Connector)
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, client); err != nil {
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, client, config.AbapAddonAssemblyKitOriginHash); err != nil {
return err
}
@ -49,7 +49,7 @@ func runAbapAddonAssemblyKitRegisterPackages(config *abapAddonAssemblyKitRegiste
}
conn2 := new(abapbuild.Connector) // we need a second connector without the added Header
if err := conn2.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, client); err != nil {
if err := conn2.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, client, config.AbapAddonAssemblyKitOriginHash); err != nil {
return err
}

View File

@ -18,10 +18,11 @@ import (
)
type abapAddonAssemblyKitRegisterPackagesOptions struct {
AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
AddonDescriptor string `json:"addonDescriptor,omitempty"`
AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
AddonDescriptor string `json:"addonDescriptor,omitempty"`
AbapAddonAssemblyKitOriginHash string `json:"abapAddonAssemblyKitOriginHash,omitempty"`
}
type abapAddonAssemblyKitRegisterPackagesCommonPipelineEnvironment struct {
@ -91,6 +92,7 @@ For Terminology refer to the [Scenario Description](https://www.project-piper.io
}
log.RegisterSecret(stepConfig.Username)
log.RegisterSecret(stepConfig.Password)
log.RegisterSecret(stepConfig.AbapAddonAssemblyKitOriginHash)
if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 {
sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID)
@ -164,6 +166,7 @@ func addAbapAddonAssemblyKitRegisterPackagesFlags(cmd *cobra.Command, stepConfig
cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for the Addon Assembly Kit as a Service (AAKaaS) system")
cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for the Addon Assembly Kit as a Service (AAKaaS) system")
cmd.Flags().StringVar(&stepConfig.AddonDescriptor, "addonDescriptor", os.Getenv("PIPER_addonDescriptor"), "Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions")
cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitOriginHash, "abapAddonAssemblyKitOriginHash", os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"), "Origin Hash for restricted AAKaaS scenarios")
cmd.MarkFlagRequired("abapAddonAssemblyKitEndpoint")
cmd.MarkFlagRequired("username")
@ -226,6 +229,15 @@ func abapAddonAssemblyKitRegisterPackagesMetadata() config.StepData {
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_addonDescriptor"),
},
{
Name: "abapAddonAssemblyKitOriginHash",
ResourceRef: []config.ResourceReference{},
Scope: []string{"PARAMETERS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"),
},
},
},
Outputs: config.StepOutputs{

View File

@ -24,7 +24,7 @@ func abapAddonAssemblyKitReleasePackages(config abapAddonAssemblyKitReleasePacka
func runAbapAddonAssemblyKitReleasePackages(config *abapAddonAssemblyKitReleasePackagesOptions, telemetryData *telemetry.CustomData, utils *aakaas.AakUtils,
cpe *abapAddonAssemblyKitReleasePackagesCommonPipelineEnvironment) error {
conn := new(abapbuild.Connector)
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, *utils); err != nil {
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, *utils, config.AbapAddonAssemblyKitOriginHash); err != nil {
return err
}
var addonDescriptor abaputils.AddonDescriptor

View File

@ -18,12 +18,13 @@ import (
)
type abapAddonAssemblyKitReleasePackagesOptions struct {
AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
AddonDescriptor string `json:"addonDescriptor,omitempty"`
MaxRuntimeInMinutes int `json:"maxRuntimeInMinutes,omitempty"`
PollingIntervalInSeconds int `json:"pollingIntervalInSeconds,omitempty"`
AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
AddonDescriptor string `json:"addonDescriptor,omitempty"`
MaxRuntimeInMinutes int `json:"maxRuntimeInMinutes,omitempty"`
PollingIntervalInSeconds int `json:"pollingIntervalInSeconds,omitempty"`
AbapAddonAssemblyKitOriginHash string `json:"abapAddonAssemblyKitOriginHash,omitempty"`
}
type abapAddonAssemblyKitReleasePackagesCommonPipelineEnvironment struct {
@ -89,6 +90,7 @@ For Terminology refer to the [Scenario Description](https://www.project-piper.io
log.SetErrorCategory(log.ErrorConfiguration)
return err
}
log.RegisterSecret(stepConfig.AbapAddonAssemblyKitOriginHash)
if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 {
sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID)
@ -164,6 +166,7 @@ func addAbapAddonAssemblyKitReleasePackagesFlags(cmd *cobra.Command, stepConfig
cmd.Flags().StringVar(&stepConfig.AddonDescriptor, "addonDescriptor", os.Getenv("PIPER_addonDescriptor"), "Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions")
cmd.Flags().IntVar(&stepConfig.MaxRuntimeInMinutes, "maxRuntimeInMinutes", 5, "Maximum runtime for status polling in minutes")
cmd.Flags().IntVar(&stepConfig.PollingIntervalInSeconds, "pollingIntervalInSeconds", 30, "Wait time in seconds between polling calls")
cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitOriginHash, "abapAddonAssemblyKitOriginHash", os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"), "Origin Hash for restricted AAKaaS scenarios")
cmd.MarkFlagRequired("abapAddonAssemblyKitEndpoint")
cmd.MarkFlagRequired("username")
@ -244,6 +247,15 @@ func abapAddonAssemblyKitReleasePackagesMetadata() config.StepData {
Aliases: []config.Alias{},
Default: 30,
},
{
Name: "abapAddonAssemblyKitOriginHash",
ResourceRef: []config.ResourceReference{},
Scope: []string{"PARAMETERS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"),
},
},
},
Outputs: config.StepOutputs{

View File

@ -30,7 +30,7 @@ func runAbapAddonAssemblyKitReserveNextPackages(config *abapAddonAssemblyKitRese
log.Entry().Infof("... initializing connection to AAKaaS @ %v", config.AbapAddonAssemblyKitEndpoint)
conn := new(abapbuild.Connector)
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, *utils); err != nil {
if err := conn.InitAAKaaS(config.AbapAddonAssemblyKitEndpoint, config.Username, config.Password, *utils, config.AbapAddonAssemblyKitOriginHash); err != nil {
return err
}

View File

@ -18,12 +18,13 @@ import (
)
type abapAddonAssemblyKitReserveNextPackagesOptions struct {
AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
AddonDescriptor string `json:"addonDescriptor,omitempty"`
MaxRuntimeInMinutes int `json:"maxRuntimeInMinutes,omitempty"`
PollingIntervalInSeconds int `json:"pollingIntervalInSeconds,omitempty"`
AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
AddonDescriptor string `json:"addonDescriptor,omitempty"`
MaxRuntimeInMinutes int `json:"maxRuntimeInMinutes,omitempty"`
PollingIntervalInSeconds int `json:"pollingIntervalInSeconds,omitempty"`
AbapAddonAssemblyKitOriginHash string `json:"abapAddonAssemblyKitOriginHash,omitempty"`
}
type abapAddonAssemblyKitReserveNextPackagesCommonPipelineEnvironment struct {
@ -95,6 +96,7 @@ For Terminology refer to the [Scenario Description](https://www.project-piper.io
}
log.RegisterSecret(stepConfig.Username)
log.RegisterSecret(stepConfig.Password)
log.RegisterSecret(stepConfig.AbapAddonAssemblyKitOriginHash)
if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 {
sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID)
@ -170,6 +172,7 @@ func addAbapAddonAssemblyKitReserveNextPackagesFlags(cmd *cobra.Command, stepCon
cmd.Flags().StringVar(&stepConfig.AddonDescriptor, "addonDescriptor", os.Getenv("PIPER_addonDescriptor"), "Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions")
cmd.Flags().IntVar(&stepConfig.MaxRuntimeInMinutes, "maxRuntimeInMinutes", 5, "Maximum runtime for status polling in minutes")
cmd.Flags().IntVar(&stepConfig.PollingIntervalInSeconds, "pollingIntervalInSeconds", 30, "Wait time in seconds between polling calls")
cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitOriginHash, "abapAddonAssemblyKitOriginHash", os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"), "Origin Hash for restricted AAKaaS scenarios")
cmd.MarkFlagRequired("abapAddonAssemblyKitEndpoint")
cmd.MarkFlagRequired("username")
@ -250,6 +253,15 @@ func abapAddonAssemblyKitReserveNextPackagesMetadata() config.StepData {
Aliases: []config.Alias{},
Default: 30,
},
{
Name: "abapAddonAssemblyKitOriginHash",
ResourceRef: []config.ResourceReference{},
Scope: []string{"PARAMETERS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"),
},
},
},
Outputs: config.StepOutputs{

View File

@ -147,7 +147,7 @@ func TestTargetVectorCreate(t *testing.T) {
mc := abapbuild.NewMockClient()
mc.AddData(AAKaaSHead)
mc.AddData(AAKaaSTVCreatePost)
errInitConn := conn.InitAAKaaS("", "dummyUser", "dummyPassword", &mc)
errInitConn := conn.InitAAKaaS("", "dummyUser", "dummyPassword", &mc, "")
assert.NoError(t, errInitConn)
errInitTV := targetVector.InitNew(&addonDescriptor)
@ -171,7 +171,7 @@ func TestTargetVectorPublish(t *testing.T) {
mc := abapbuild.NewMockClient()
mc.AddData(AAKaaSHead)
mc.AddData(AAKaaSTVPublishTestPost)
errInitConn := conn.InitAAKaaS("", "dummyUser", "dummyPassword", &mc)
errInitConn := conn.InitAAKaaS("", "dummyUser", "dummyPassword", &mc, "")
assert.NoError(t, errInitConn)
//act

View File

@ -130,12 +130,16 @@ func (conn Connector) createUrl(appendum string) string {
}
// InitAAKaaS : initialize Connector for communication with AAKaaS backend
func (conn *Connector) InitAAKaaS(aAKaaSEndpoint string, username string, password string, inputclient piperhttp.Sender) error {
func (conn *Connector) InitAAKaaS(aAKaaSEndpoint string, username string, password string, inputclient piperhttp.Sender, originHash string) error {
conn.Client = inputclient
conn.Header = make(map[string][]string)
conn.Header["Accept"] = []string{"application/json"}
conn.Header["Content-Type"] = []string{"application/json"}
conn.Header["User-Agent"] = []string{"Piper-abapAddonAssemblyKit/1.0"}
if originHash != "" {
conn.Header["build-config-token"] = []string{originHash}
log.Entry().Info("Origin info for restricted scenario added")
}
cookieJar, _ := cookiejar.New(nil)
conn.Client.SetOptions(piperhttp.ClientOptions{

View File

@ -4,13 +4,43 @@
package build
import (
"bytes"
"fmt"
"io"
"net/http"
"net/url"
"testing"
"time"
"golang.org/x/exp/slices" //in 1.21 will be a standard package "slices"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/stretchr/testify/assert"
)
type HeaderVerifyingMockClient struct {
Header map[string][]string
}
func (mc *HeaderVerifyingMockClient) SetOptions(opts piperhttp.ClientOptions) {}
func (mc *HeaderVerifyingMockClient) SendRequest(Method, Url string, bdy io.Reader, hdr http.Header, cookies []*http.Cookie) (*http.Response, error) {
for requiredHeaderKey, requiredHeaderValues := range mc.Header {
suppliedHeaderValues, existingHeader := hdr[requiredHeaderKey]
if existingHeader {
for _, element := range requiredHeaderValues {
existingValue := slices.Contains(suppliedHeaderValues, element)
if !existingValue {
return nil, fmt.Errorf("header %s does not contain expected value %s", requiredHeaderKey, element)
}
}
} else {
return nil, fmt.Errorf("Expected header %s not part of the http request", requiredHeaderKey)
}
}
return &http.Response{Body: io.NopCloser(bytes.NewReader([]byte("")))}, nil
}
func TestCreateUrl(t *testing.T) {
//arrange global
conn := new(Connector)
@ -59,3 +89,36 @@ func TestCreateUrl(t *testing.T) {
assert.Equal(t, "/BUILD/CORE_SRV/builds('123456789')?format=json&sap-client=001&top=2", url)
})
}
func TestInitAAKaaSHeader(t *testing.T) {
conn := new(Connector)
client := HeaderVerifyingMockClient{}
client.Header = make(map[string][]string)
client.Header["Accept"] = []string{"application/json"}
client.Header["Content-Type"] = []string{"application/json"}
client.Header["User-Agent"] = []string{"Piper-abapAddonAssemblyKit/1.0"}
t.Run("InitAAKaaS success no hash", func(t *testing.T) {
conn.InitAAKaaS("endpoint", "user", "pw", &client, "")
_, err := conn.Get("something")
assert.NoError(t, err)
})
t.Run("InitAAKaaS success with hash", func(t *testing.T) {
client.Header["build-config-token"] = []string{"hash"}
conn.InitAAKaaS("endpoint", "user", "pw", &client, "hash")
_, err := conn.Get("something")
assert.NoError(t, err)
})
t.Run("InitAAKaaS sanity check Header", func(t *testing.T) {
client.Header["FAIL"] = []string{"verify HeaderVerifyingMockClient works"}
conn.InitAAKaaS("endpoint", "user", "pw", &client, "hash")
_, err := conn.Get("something")
assert.Error(t, err)
})
t.Run("InitAAKaaS sanity check wrong Value in existing Header", func(t *testing.T) {
client.Header["Accept"] = []string{"verify HeaderVerifyingMockClient works"}
conn.InitAAKaaS("endpoint", "user", "pw", &client, "hash")
_, err := conn.Get("something")
assert.Error(t, err)
})
}

View File

@ -91,7 +91,6 @@ func (mc *MockClient) SetOptions(opts piperhttp.ClientOptions) {}
func (mc *MockClient) SendRequest(Method, Url string, bdy io.Reader, hdr http.Header, cookies []*http.Cookie) (*http.Response, error) {
response, ok := mc.getResponse(Method, Url)
if !ok {
//return nil, errors.New("No Mock data for given Method+Url")
return nil, fmt.Errorf("No Mock data for %s", Method+Url)
}
return &response, nil

View File

@ -51,6 +51,13 @@ spec:
resourceRef:
- name: commonPipelineEnvironment
param: abap/addonDescriptor
- name: abapAddonAssemblyKitOriginHash
type: string
description: Origin Hash for restricted AAKaaS scenarios
scope:
- PARAMETERS
mandatory: false
secret: true
outputs:
resources:
- name: commonPipelineEnvironment

View File

@ -79,3 +79,10 @@ spec:
resourceRef:
- name: commonPipelineEnvironment
param: abap/addonDescriptor
- name: abapAddonAssemblyKitOriginHash
type: string
description: Origin Hash for restricted AAKaaS scenarios
scope:
- PARAMETERS
mandatory: false
secret: true

View File

@ -53,6 +53,13 @@ spec:
resourceRef:
- name: commonPipelineEnvironment
param: abap/addonDescriptor
- name: abapAddonAssemblyKitOriginHash
type: string
description: Origin Hash for restricted AAKaaS scenarios
scope:
- PARAMETERS
mandatory: false
secret: true
outputs:
resources:
- name: commonPipelineEnvironment

View File

@ -66,6 +66,13 @@ spec:
- STEPS
- GENERAL
default: 30
- name: abapAddonAssemblyKitOriginHash
type: string
description: Origin Hash for restricted AAKaaS scenarios
scope:
- PARAMETERS
mandatory: false
secret: true
outputs:
resources:
- name: commonPipelineEnvironment

View File

@ -72,6 +72,13 @@ spec:
- STEPS
- GENERAL
default: 30
- name: abapAddonAssemblyKitOriginHash
type: string
description: Origin Hash for restricted AAKaaS scenarios
scope:
- PARAMETERS
mandatory: false
secret: true
outputs:
resources:
- name: commonPipelineEnvironment