|
package tests
import (
httputils "github.com/RedHatInsights/insights-operator-utils/http"
"github.com/RedHatInsights/insights-results-aggregator-data/testdata"
"github.com/verdverm/frisby"
"github.com/RedHatInsights/insights-results-aggregator/server"
"github.com/RedHatInsights/insights-results-aggregator/types"
)
|
constructURLForReportForOrgCluster function constructs an URL to access the
endpoint to retrieve results for given cluster from selected organization
|
func constructURLForReportForOrgCluster ( organizationID , clusterID string , userID types . UserID ) string {
return httputils . MakeURLToEndpoint ( apiURL , server . ReportEndpoint , organizationID , clusterID , userID )
}
|
checkReportEndpointForKnownOrganizationAndKnownCluster check if the endpoint to return report works as expected
|
func checkReportEndpointForKnownOrganizationAndKnownCluster ( ) {
url := constructURLForReportForOrgCluster ( "1" , knownClusterForOrganization1 , testdata . UserID )
f := frisby . Create ( "Check the endpoint to return report for existing organization and cluster ID" ) . Get ( url )
setAuthHeader ( f )
f . Send ( )
f . ExpectStatus ( 200 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
f . PrintReport ( )
}
|
checkReportEndpointForKnownOrganizationAndUnknownCluster check if the endpoint to return report works as expected
|
func checkReportEndpointForKnownOrganizationAndUnknownCluster ( ) {
url := constructURLForReportForOrgCluster ( "1" , unknownClusterForOrganization1 , testdata . UserID )
f := frisby . Create ( "Check the endpoint to return report for existing organization and non-existing cluster ID" ) . Get ( url )
setAuthHeader ( f )
f . Send ( )
f . ExpectStatus ( 404 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
f . PrintReport ( )
}
|
checkReportEndpointForUnknownOrganizationAndKnownCluster check if the endpoint to return report works as expected
|
func checkReportEndpointForUnknownOrganizationAndKnownCluster ( ) {
url := constructURLForReportForOrgCluster ( unknownOrganizationID , knownClusterForOrganization1 , testdata . UserID )
f := frisby . Create ( "Check the endpoint to return report for non-existing organization and non-existing cluster ID" ) . Get ( url )
setAuthHeaderForOrganization ( f , 100000 )
f . Send ( )
f . ExpectStatus ( 404 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
f . PrintReport ( )
}
|
checkReportEndpointForUnknownOrganizationAndUnknownCluster check if the endpoint to return report works as expected
|
func checkReportEndpointForUnknownOrganizationAndUnknownCluster ( ) {
url := constructURLForReportForOrgCluster ( unknownOrganizationID , unknownClusterForOrganization1 , testdata . UserID )
f := frisby . Create ( "Check the endpoint to return report for non-existing organization and non-existing cluster ID" ) . Get ( url )
setAuthHeaderForOrganization ( f , 100000 )
f . Send ( )
f . ExpectStatus ( 404 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
f . PrintReport ( )
}
|
reproducerForIssue384 checks whether the issue https://github.com/RedHatInsights/insights-results-aggregator/issues/384 has been fixed
|
func reproducerForIssue384 ( ) {
url := constructURLForReportForOrgCluster ( "000000000000000000000000000000000000" , "1" , testdata . UserID )
f := frisby . Create ( "Reproducer for issue #384 (https://github.com/RedHatInsights/insights-results-aggregator/issues/384)" ) . Get ( url )
setAuthHeader ( f )
f . Send ( )
f . ExpectStatus ( 400 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
f . PrintReport ( )
}
|
checkReportEndpointForImproperOrganization check if the endpoint to return report works as expected
|
func checkReportEndpointForImproperOrganization ( ) {
url := constructURLForReportForOrgCluster ( wrongOrganizationID , knownClusterForOrganization1 , testdata . UserID )
f := frisby . Create ( "Check the endpoint to return report for improper organization" ) . Get ( url )
setAuthHeader ( f )
f . Send ( )
f . ExpectStatus ( 400 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
statusResponse := readStatusFromResponse ( f )
checkErrorStatusResponse ( f , statusResponse )
f . PrintReport ( )
}
|
checkReportEndpointWrongMethods check if the endpoint to return results responds correctly to other methods than HTTP GET
|
func checkReportEndpointWrongMethods ( ) {
url := constructURLForReportForOrgCluster ( "1" , knownClusterForOrganization1 , testdata . UserID )
checkGetEndpointByOtherMethods ( url , false )
}
|
checkReportEndpointForKnownOrganizationAndKnownClusterUnauthorizedCase check if the endpoint to return report works as expected
This test variant does not sent authorization header
|
func checkReportEndpointForKnownOrganizationAndKnownClusterUnauthorizedCase ( ) {
url := constructURLForReportForOrgCluster ( "1" , knownClusterForOrganization1 , testdata . UserID )
f := frisby . Create ( "Check the endpoint to return report for existing organization and cluster ID w/o authorization token" ) . Get ( url )
f . Send ( )
f . ExpectStatus ( 401 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
statusResponse := readStatusFromResponse ( f )
checkErrorStatusResponse ( f , statusResponse )
f . PrintReport ( )
}
|
checkReportEndpointForKnownOrganizationAndUnknownClusterUnauthorizedCase check if the endpoint to return report works as expected
This test variant does not sent authorization header
|
func checkReportEndpointForKnownOrganizationAndUnknownClusterUnauthorizedCase ( ) {
url := constructURLForReportForOrgCluster ( "1" , unknownClusterForOrganization1 , testdata . UserID )
f := frisby . Create ( "Check the endpoint to return report for existing organization and non-existing cluster ID w/o authorization token" ) . Get ( url )
f . Send ( )
f . ExpectStatus ( 401 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
statusResponse := readStatusFromResponse ( f )
checkErrorStatusResponse ( f , statusResponse )
f . PrintReport ( )
}
|
checkReportEndpointForUnknownOrganizationAndKnownClusterUnauthorizedCase check if the endpoint to return report works as expected
This test variant does not sent authorization header
|
func checkReportEndpointForUnknownOrganizationAndKnownClusterUnauthorizedCase ( ) {
url := constructURLForReportForOrgCluster ( unknownOrganizationID , knownClusterForOrganization1 , testdata . UserID )
f := frisby . Create ( "Check the endpoint to return report for non-existing organization and non-existing cluster ID w/o authorization token" ) . Get ( url )
f . Send ( )
f . ExpectStatus ( 401 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
statusResponse := readStatusFromResponse ( f )
checkErrorStatusResponse ( f , statusResponse )
f . PrintReport ( )
}
|
checkReportEndpointForUnknownOrganizationAndUnknownClusterUnauthorizedCase check if the endpoint to return report works as expected
This test variant does not sent authorization header
|
func checkReportEndpointForUnknownOrganizationAndUnknownClusterUnauthorizedCase ( ) {
url := constructURLForReportForOrgCluster ( unknownOrganizationID , unknownClusterForOrganization1 , testdata . UserID )
f := frisby . Create ( "Check the endpoint to return report for non-existing organization and non-existing cluster ID w/o authorization token" ) . Get ( url )
f . Send ( )
f . ExpectStatus ( 401 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
statusResponse := readStatusFromResponse ( f )
checkErrorStatusResponse ( f , statusResponse )
f . PrintReport ( )
}
|
checkReportEndpointForImproperOrganizationUnauthorizedCase check if the endpoint to return report works as expected
This test variant does not sent authorization header
|
func checkReportEndpointForImproperOrganizationUnauthorizedCase ( ) {
url := constructURLForReportForOrgCluster ( wrongOrganizationID , knownClusterForOrganization1 , testdata . UserID )
f := frisby . Create ( "Check the endpoint to return report for improper organization w/o authorization token" ) . Get ( url )
f . Send ( )
f . ExpectStatus ( 401 )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
statusResponse := readStatusFromResponse ( f )
checkErrorStatusResponse ( f , statusResponse )
f . PrintReport ( )
}
|