X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Fmain_test.go;h=f174fe31dd9d8e7b9094197f82f290691240e958;hb=55e8dfc4ed1ffa5877ee8517a05a3b36d34d4882;hp=12092c1b28c795eaa5192ee0df478aeb5e7dcbfc;hpb=b4da1f981ba6717f5ec52e15ad1db257b5d6b7f3;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/main_test.go b/capifcore/main_test.go index 12092c1..f174fe3 100644 --- a/capifcore/main_test.go +++ b/capifcore/main_test.go @@ -2,7 +2,8 @@ // ========================LICENSE_START================================= // O-RAN-SC // %% -// Copyright (C) 2022: Nordix Foundation +// Copyright (C) 2022: Nordix Foundation. All rights reserved. +// Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved. // %% // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,8 +22,12 @@ package main import ( + "crypto/tls" + "fmt" + "io" "net/http" "testing" + "time" "github.com/deepmap/oapi-codegen/pkg/testutil" "github.com/getkin/kin-openapi/openapi3" @@ -85,11 +90,19 @@ func Test_routing(t *testing.T) { method: "DELETE", }, }, + { + name: "Event path", + args: args{ + url: "/capif-events/v1/subscriberId/subscriptions/subId", + returnStatus: http.StatusNoContent, + method: "DELETE", + }, + }, { name: "Security path", args: args{ url: "/capif-security/v1/trustedInvokers/apiInvokerId", - returnStatus: http.StatusNotImplemented, + returnStatus: http.StatusNotFound, method: "GET", }, }, @@ -140,6 +153,13 @@ func TestGetSwagger(t *testing.T) { apiName: "Invoker", }, }, + { + name: "Events api", + args: args{ + apiPath: "events", + apiName: "Events", + }, + }, { name: "Discover api", args: args{ @@ -174,3 +194,32 @@ func TestGetSwagger(t *testing.T) { assert.Contains(t, *errorResponse.Cause, "Invalid API") assert.Contains(t, *errorResponse.Cause, invalidApi) } + +func TestHTTPSServer(t *testing.T) { + e = getEcho() + var port = 44333 + go startHttpsWebServer(e, 44333, "certs/cert.pem", "certs/key.pem") //"certs/test/cert.pem", "certs/test/key.pem" + + time.Sleep(100 * time.Millisecond) + + tr := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + + client := &http.Client{Transport: tr} + res, err := client.Get(fmt.Sprintf("https://localhost:%d", port)) + if err != nil { + t.Fatal(err) + } + + defer res.Body.Close() + assert.Equal(t, res.StatusCode, res.StatusCode) + + body, err := io.ReadAll(res.Body) + if err != nil { + t.Fatal(err) + } + + expected := []byte("Hello, World!") + assert.Equal(t, expected, body) +}