<commit_before>#!/bin/sh
################################################################################
#
# Copyright (C) 2018 Neighborhood Guard, Inc.  All rights reserved.
# Original author: <NAME>
# 
# This file is part of FTP_Upload.
# 
# FTP_Upload is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# FTP_Upload is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with FTP_Upload.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

UNIT_TEST_IN_PROGRESS=1

wd=`pwd`
cd ..
. ./confcvserver.sh
cd $wd

test_editnpconf_no_file() {
    assertFalse "Should fail on missing conf file" \
        "editnpconf this_is_a_bogus_filename foo bar"
}

test_editnpconf_wrong_number_of_args() {
    assertFalse "Should fail with only two args" \
        "editnpconf testConfcvserver.sh foo"
}

test_editnpconf_name_value_editing() {
    # initial conf file before editing
    local i=""
    i=${i}'# Test conf file\n'
    i=${i}'# DefaultRoot <- this should not get edited\n'
    i=${i}'# next line is indented and contains multiple spaces\n'
    i=${i}'    PassivePorts    100    200\n'
    i=${i}'\tNameSurroundedByTabs\t100    200\n'
    i=${i}'MasqueradeAddress blah\n'
    i=${i}'# End of initial conf file\n'
    local tcf=unit_test_temp_conf_file
    local tof=unit_test_temp_orig_file
    /bin/echo -ne "$i" > $tcf
    /bin/echo -ne "$i" > $tof    # for debugging

    editnpconf $tcf DefaultRoot \~
    editnpconf $tcf PassivePorts "60000 60999"
    editnpconf $tcf NameSurroundedByTabs "3   4"
    editnpconf $tcf RequireValidShell off
    editnpconf $tcf MasqueradeAddress 1.2.3.4

    # excpected conf file after editing
    o=${o}'# Test conf file\n'
    o=${o}'# DefaultRoot <- this should not get edited\n'
    o=${o}'# next line is indented and contains multiple spaces\n'
    o=${o}'    PassivePorts    60000 60999\n'
    o=${o}'\tNameSurroundedByTabs\t3   4\n'
    o=${o}'MasqueradeAddress 1.2.3.4\n'
    o=${o}'# End of initial conf file\n'
    o=${o}'DefaultRoot ~\n'
    o=${o}'RequireValidShell off\n'
    local tef=unit_test_temp_expctd_file
    /bin/echo -ne "$o" > $tef

    local diffs=`diff $tef $tcf`
    local status=$?
    if [ $status -ne 0 ]
    then
        fail "Output differs from expected:"
        echo "$diffs"
    else
        rm $tef $tcf $tof
    fi
}

#
# Test the editcrontab function for proper operation<commit_msg>Add test for editnpconf bug fix<commit_after>#!/bin/sh
################################################################################
#
# Copyright (C) 2018 Neighborhood Guard, Inc.  All rights reserved.
# Original author: <NAME>
# 
# This file is part of FTP_Upload.
# 
# FTP_Upload is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# FTP_Upload is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with FTP_Upload.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

UNIT_TEST_IN_PROGRESS=1

wd=`pwd`
cd ..
. ./confcvserver.sh
cd $wd

test_editnpconf_no_file() {
    assertFalse "Should fail on missing conf file" \
        "editnpconf this_is_a_bogus_filename foo bar"
}

test_editnpconf_wrong_number_of_args() {
    assertFalse "Should fail with only two args" \
        "editnpconf testConfcvserver.sh foo"
}

test_editnpconf_name_value_editing() {
    # initial conf file before editing
    local i=""
    i=${i}'# Test conf file\n'
    i=${i}'# DefaultRoot <- this should not get edited\n'
    i=${i}'# next line is indented and contains multiple spaces\n'
    i=${i}'    PassivePorts    100    200\n'
    i=${i}'\tNameSurroundedByTabs\t100    200\n'
    i=${i}'ExistingDirectiveWithSpecialChars ~\n'
    i=${i}'MasqueradeAddress blah\n'
    i=${i}'# End of initial conf file\n'
    local tcf=unit_test_temp_conf_file
    local tof=unit_test_temp_orig_file
    /bin/echo -ne "$i" > $tcf
    /bin/echo -ne "$i" > $tof    # for debugging

    editnpconf $tcf DefaultRoot \~
    editnpconf $tcf PassivePorts "60000 60999"
    editnpconf $tcf NameSurroundedByTabs "3   4"
    editnpconf $tcf RequireValidShell off
    editnpconf $tcf MasqueradeAddress 1.2.3.4
    editnpconf $tcf NewDirectiveWithSpecialChars '~/fooagain baragain'
    editnpconf $tcf ExistingDirectiveWithSpecialChars '~/foo bar'

    # excpected conf file after editing
    o=${o}'# Test conf file\n'
    o=${o}'# DefaultRoot <- this should not get edited\n'
    o=${o}'# next line is indented and contains multiple spaces\n'
    o=${o}'    PassivePorts    60000 60999\n'
    o=${o}'\tNameSurroundedByTabs\t3   4\n'
    o=${o}'ExistingDirectiveWithSpecialChars ~/foo bar\n'
    o=${o}'MasqueradeAddress 1.2.3.4\n'
    o=${o}'# End of initial conf file\n'
    o=${o}'DefaultRoot ~\n'
    o=${o}'RequireValidShell off\n'
    o=${o}'NewDirectiveWithSpecialChars ~/fooagain baragain\n'
    local tef=unit_test_temp_expctd_file
    /bin/echo -ne "$o" > $tef

    local diffs=`diff $tef $tcf`
    local status=$?
    if [ $status -ne 0 ]
    then
        fail "Output differs from expected:"
        echo "$diffs"
    else
        rm $tef $tcf $tof
    fi
}

#
# Test the editcrontab function for proper operation
{'fraction_non_alphanumeric': 0.15455140798952194, 'fraction_numerical': 0.01669941060903733, 'mean_word_length': 3.5555555555555554, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3012741', 'n_tokens_mistral': 2082, 'n_tokens_neox': 1964, 'n_words': 630}