<commit_before>#!/bin/bash

# beakerlib-satellite-xmlrpc.sh - BeakerLib extension for RHN Satellite XML-RPC tests
# Authors: <NAME> <<EMAIL>@>
#
# Description: Extends BeakerLib with rlSatellite* functions
#
# TODO: license?

: <<=cut
=pod

=head1 NAME

beakerlib-satellite-xmlrpc.sh - BeakerLib extension for RHN Satellite XML-RPC tests

=head1 DESCRIPTION

This file contains functions related directly to testing. These functions are
non-specialized asserts, as well as several other functions related to testing.  

This file contains functions for easier testing of XML-RPC interface of
RHN Satellite server.

=head1 FUNCTIONS

=cut

Tomcat6LogFile="/var/log/tomcat6/catalina.out"
HttpdErrorLogFile="/var/log/httpd/error_log"

# TODO: which path is default?
SATELLITE_XMLRPC_SCRIPTS=${SATELLITE_XMLRPC_SCRIPTS:-"/some/default/path"}

SATELLITE_VERSION=${SATELLITE_VERSION:-"1.2"}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#   Internal Stuff
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

__INTERNAL_LogAndJournalPass() {
    rljAddTest "$1" "PASS"
}

__INTERNAL_LogAndJournalFail() {
    rljAddTest "$1 $2" "FAIL"
}

__INTERNAL_SatelliteXmlRpcRun() {
    local scriptName=$( cut -d" " -f1 <<< $2 )
    local scriptExpanded=""
    local basePath="$SATELLITE_XMLRPC_SCRIPTS/$1"
    
    if [ -e "$basePath/$SATELLITE_VERSION/$scriptName" ]; then
        scriptExpanded="$basePath/$SATELLITE_VERSION/$2"
    else
        scriptExpanded="$basePath/$2"
    fi

    # resolve the absolute path
    scriptExpanded=$( readlink -f "$scriptExpanded" )

    rlRun -s -l -t "$scriptExpanded" 0
    return 0
}

__INTERNAL_AssertLogNotDiffer(){
    if [ ! -e "$1" ]; then
        __INTERNAL_LogAndJournalFail "__INTERNAL_AssertLogNotDiffer cannot assert because log has not been probably saved before"
        return 1
    fi 

    AdditionTmpFile=$( mktemp )

    # Get just the new lines and strip the ">  " prefix
    diff "$1" "$2" | grep "^> " | cut -c 3- > "$AdditionTmpFile"

    # if addition is not empty
    if [ -s "$AdditionTmpFile" ]; then
        __INTERNAL_LogAndJournalFail "$3"
        rlLog "`cat $AdditionTmpFile`"
        return 1
    fi
    
    rm -f $AdditionTmpFile

    __INTERNAL_LogAndJournalPass "$3"
    return 0
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteXmlRpcFrontendRun                                                                 
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: <<=cut                                                                       
=pod                                                                           

=head3 rlSatelliteXmlRpcFrontendRun

Run the given XML-RPC script from library (actual path is affected by version
of RHN Satellite) against Satellite frontend API.

    rlSatelliteXmlRpcFrontendRun script

Output of the script is accessible in file of name specified in $rlRun_LOG 
variable. Caller is responsible for removing the file.

=over

=item script

The script which should be run from library, e.g. "auth.login.py admin redhat".

=back

Returns 0 and asserts PASS if the return value of script is 0 (FAIL otherwise).

=cut

rlSatelliteXmlRpcFrontendRun(){
    __INTERNAL_SatelliteXmlRpcRun "frontend" $1

    return $?
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteXmlRpcBackendRun                                                                 
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: <<=cut                                                                       
=pod                                                                           

=head3 rlSatelliteXmlRpcBackendRun

Run the given XML-RPC script from library (actual path is affected by version
of RHN Satellite) against Satellite backend API.

    rlSatelliteXmlRpcBackendRun script

Output of the script is accessible in file of name specified in $rlRun_LOG 
variable. Caller is responsible for removing the file.

=over

=item script

The script which should be run from library, e.g. "registration.welcome_message.py".

=back

Returns 0 and asserts PASS if the return value of script is 0 (FAIL otherwise).

=cut

rlSatelliteXmlRpcBackendRun(){
    __INTERNAL_SatelliteXmlRpcRun "backend" $1

    return $?
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteSaveTomcat6Log
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

rlSatelliteSaveTomcat6Log(){
    rlRun "Tomcat6LogSaved=\`mktemp\`" 0 \
          "Creating the temporary file for tomcat6 log file"
    rlRun "cat $Tomcat6LogFile > $Tomcat6LogSaved" 0 \
          "Storing the contents of $Tomcat6LogFile"
    export Tomcat6LogSaved

    return 0
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteSaveHttpdErrorLog
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

rlSatelliteSaveHttpdErrorLog(){
    rlRun "HttpdErrorLogSaved=\`mktemp\`" 0 \
          "Creating the temporary file for httpd error log file"
    rlRun "cat $HttpdErrorLogFile > $HttpdErrorLogSaved" 0 \
          "Storing the contents of $HttpdErrorLogFile"
    export HttpdErrorLogSaved

    return 0
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteAssertTomcat6LogNotDiffer
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

rlSatelliteAssertTomcat6LogNotDiffer(){
    __INTERNAL_AssertLogNotDiffer "$Tomcat6LogSaved" "$Tomcat6LogFile" \
        "There should not be any addition to tomcat6 log"

    return $?
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteAssertHttpdErrorLogNotDiffer
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

rlSatelliteAssertHttpdErrorLogNotDiffer(){
    __INTERNAL_AssertLogNotDiffer "$HttpdErrorLogSaved" "$HttpdErrorLogFile" \
        "There should not be any addition to httpd error log"

    return $?
}

<commit_msg>Comments in the BeakerLib plugin.<commit_after>#!/bin/bash

# beakerlib-satellite-xmlrpc.sh - BeakerLib extension for RHN Satellite XML-RPC tests
# Authors: <NAME> <<EMAIL>@>
#
# Description: Extends BeakerLib with rlSatellite* functions
#
# TODO: license?

: <<=cut
=pod

=head1 NAME

beakerlib-satellite-xmlrpc.sh - BeakerLib extension for RHN Satellite XML-RPC tests

=head1 DESCRIPTION

This file contains functions related directly to testing. These functions are
non-specialized asserts, as well as several other functions related to testing.  

This file contains functions for easier testing of XML-RPC interface of
RHN Satellite server.

=head1 FUNCTIONS

=cut

Tomcat6LogFile="/var/log/tomcat6/catalina.out"
HttpdErrorLogFile="/var/log/httpd/error_log"

# TODO: which path is default?
SATELLITE_XMLRPC_SCRIPTS=${SATELLITE_XMLRPC_SCRIPTS:-"/some/default/path"}

SATELLITE_VERSION=${SATELLITE_VERSION:-"1.2"}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#   Internal Stuff
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

__INTERNAL_LogAndJournalPass() {
    rljAddTest "$1" "PASS"
}

__INTERNAL_LogAndJournalFail() {
    rljAddTest "$1 $2" "FAIL"
}

__INTERNAL_SatelliteXmlRpcRun() {
    local scriptName=$( cut -d" " -f1 <<< $2 )
    local scriptExpanded=""
    local basePath="$SATELLITE_XMLRPC_SCRIPTS/$1"
    
    if [ -e "$basePath/$SATELLITE_VERSION/$scriptName" ]; then
        scriptExpanded="$basePath/$SATELLITE_VERSION/$2"
    else
        scriptExpanded="$basePath/$2"
    fi

    # resolve the absolute path
    scriptExpanded=$( readlink -f "$scriptExpanded" )

    rlRun -s -l -t "$scriptExpanded" 0
    return 0
}

__INTERNAL_AssertLogNotDiffer(){
    if [ ! -e "$1" ]; then
        __INTERNAL_LogAndJournalFail "__INTERNAL_AssertLogNotDiffer cannot assert because log has not been probably saved before"
        return 1
    fi 

    AdditionTmpFile=$( mktemp )

    # Get just the new lines and strip the ">  " prefix
    diff "$1" "$2" | grep "^> " | cut -c 3- > "$AdditionTmpFile"

    # if addition is not empty
    if [ -s "$AdditionTmpFile" ]; then
        __INTERNAL_LogAndJournalFail "$3"
        rlLog "`cat $AdditionTmpFile`"
        return 1
    fi
    
    rm -f $AdditionTmpFile

    __INTERNAL_LogAndJournalPass "$3"
    return 0
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteXmlRpcFrontendRun                                                                 
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: <<=cut                                                                       
=pod                                                                           

=head3 rlSatelliteXmlRpcFrontendRun

Run the given XML-RPC script from library (actual path is affected by version
of RHN Satellite) against Satellite frontend API.

    rlSatelliteXmlRpcFrontendRun script

Output of the script is accessible in file of name specified in $rlRun_LOG 
variable. Caller is responsible for removing the file.

=over

=item script

The script which should be run from library, e.g. "auth.login.py admin redhat".

=back

Returns 0 and asserts PASS if the return value of script is 0 (FAIL otherwise).

=cut

rlSatelliteXmlRpcFrontendRun(){
    __INTERNAL_SatelliteXmlRpcRun "frontend" $1

    return $?
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteXmlRpcBackendRun                                                                 
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: <<=cut                                                                       
=pod                                                                           

=head3 rlSatelliteXmlRpcBackendRun

Run the given XML-RPC script from library (actual path is affected by version
of RHN Satellite) against Satellite backend API.

    rlSatelliteXmlRpcBackendRun script

Output of the script is accessible in file of name specified in $rlRun_LOG 
variable. Caller is responsible for removing the file.

=over

=item script

The script which should be run from library, e.g. "registration.welcome_message.py".

=back

Returns 0 and asserts PASS if the return value of script is 0 (FAIL otherwise).

=cut

rlSatelliteXmlRpcBackendRun(){
    __INTERNAL_SatelliteXmlRpcRun "backend" $1

    return $?
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteSaveTomcat6Log
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: <<=cut                                                                       
=pod                                                                           

=head3 rlSatelliteSaveTomcat6Log

Backups the tomcat6 catalina.out log file into temporary file and sets the
variable $Tomcat6LogSaved to the name of that temporary file. Therefore
the caller is then responsible of removing it.

Returns 0.

=cut

rlSatelliteSaveTomcat6Log(){
    rlRun "Tomcat6LogSaved=\`mktemp\`" 0 \
          "Creating the temporary file for tomcat6 log file"
    rlRun "cat $Tomcat6LogFile > $Tomcat6LogSaved" 0 \
          "Storing the contents of $Tomcat6LogFile"
    export Tomcat6LogSaved

    return 0
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteSaveHttpdErrorLog
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: <<=cut                                                                       
=pod                                                                           

=head3 rlSatelliteSaveHttpdErrorLog

Backups the httpd error_log log file into temporary file and sets the
variable $HttpdErrorLogSaved to the name of that temporary file. Therefore
the caller is then responsible of removing it.

Returns 0.

=cut

rlSatelliteSaveHttpdErrorLog(){
    rlRun "HttpdErrorLogSaved=\`mktemp\`" 0 \
          "Creating the temporary file for httpd error log file"
    rlRun "cat $HttpdErrorLogFile > $HttpdErrorLogSaved" 0 \
          "Storing the contents of $HttpdErrorLogFile"
    export HttpdErrorLogSaved

    return 0
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteAssertTomcat6LogNotDiffer
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: <<=cut                                                                       
=pod                                                                           

=head3 rlSatelliteAssertTomcat6LogNotDiffer

Assertion checking that the previously saved tomcat6 catalina.out log file 
does not differ from the current one. The previously saved log file name is
expected to be in $Tomcat6LogSaved variable.

Returns 0 and asserts PASS when log files does not differ.

=cut

rlSatelliteAssertTomcat6LogNotDiffer(){
    __INTERNAL_AssertLogNotDiffer "$Tomcat6LogSaved" "$Tomcat6LogFile" \
        "There should not be any addition to tomcat6 log"

    return $?
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rlSatelliteAssertHttpdErrorLogNotDiffer
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: <<=cut                                                                       
=pod                                                                           

=head3 rlSatelliteAssertHttpdErrorLogNotDiffer

Assertion checking that the previously saved httpd error_log log file 
does not differ from the current one. The previously saved log file name is
expected to be in $HttpdErrorLogSaved variable.

Returns 0 and asserts PASS when log files does not differ.

=cut

rlSatelliteAssertHttpdErrorLogNotDiffer(){
    __INTERNAL_AssertLogNotDiffer "$HttpdErrorLogSaved" "$HttpdErrorLogFile" \
        "There should not be any addition to httpd error log"

    return $?
}


{'fraction_non_alphanumeric': 0.21288178733031674, 'fraction_numerical': 0.008484162895927601, 'mean_word_length': 2.9445064138315673, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7146162', 'n_tokens_mistral': 4038, 'n_tokens_neox': 3675, 'n_words': 1062}