merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

test_merchant_signup_email.sh (3758B)


      1 #!/usr/bin/env bash
      2 # This file is part of TALER
      3 # Copyright (C) 2026 Taler Systems SA
      4 #
      5 # TALER is free software; you can redistribute it and/or modify
      6 # it under the terms of the GNU General Public License as
      7 # published by the Free Software Foundation; either version 3, or
      8 # (at your option) any later version.
      9 #
     10 # TALER is distributed in the hope that it will be useful, but
     11 # WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU General Public
     16 # License along with TALER; see the file COPYING.  If not, see
     17 # <http://www.gnu.org/licenses/>
     18 #
     19 # Check that creating an instance with an e-mail address sends the
     20 # merchant a message with their login name.  Instead of e-mailing it,
     21 # the report generator writes the message to "$EMAIL.txt".
     22 #
     23 set -eu
     24 
     25 . setup.sh
     26 
     27 # Launch only the merchant.
     28 setup -c test_template.conf -m
     29 CONF="test_template.conf.edited"
     30 LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX)
     31 EMAIL="signup@example.com"
     32 MESSAGE="$EMAIL.txt"
     33 rm -f "$MESSAGE"
     34 
     35 function signup_cleanup()
     36 {
     37     rm -f "$LAST_RESPONSE" "$MESSAGE"
     38     exit_cleanup
     39 }
     40 trap signup_cleanup EXIT
     41 
     42 # Write "e-mails" to a file instead of sending them.
     43 taler-merchant-config \
     44     -c "$CONF" \
     45     -s report-generator-email \
     46     -o BINARY \
     47     -V taler-merchant-report-generator-file
     48 
     49 echo -n "Configuring admin instance without e-mail address ..."
     50 STATUS=$(curl -H "Content-Type: application/json" -X POST \
     51     http://localhost:9966/management/instances \
     52     -d '{"auth":{"method":"token","password":"super_secret"},"id":"admin","name":"default","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \
     53     -w "%{http_code}" -s -o "$LAST_RESPONSE")
     54 
     55 if [ "$STATUS" != "204" ]
     56 then
     57     jq < "$LAST_RESPONSE"
     58     exit_fail "Expected 204, instance created. got: $STATUS"
     59 fi
     60 ADMIN_TOKEN=$(merchant_login admin super_secret)
     61 echo " OK"
     62 
     63 echo -n "Creating instance with e-mail address ..."
     64 STATUS=$(curl -H "Content-Type: application/json" -X POST \
     65     -H "Authorization: Bearer $ADMIN_TOKEN" \
     66     http://localhost:9966/management/instances \
     67     -d '{"auth":{"method":"token","password":"pass1234"},"id":"signup","name":"Signup & Sons","email":"'"$EMAIL"'","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' \
     68     -w "%{http_code}" -s -o "$LAST_RESPONSE")
     69 
     70 if [ "$STATUS" != "204" ]
     71 then
     72     jq < "$LAST_RESPONSE"
     73     exit_fail "Expected 204, instance created. got: $STATUS"
     74 fi
     75 echo " OK"
     76 
     77 echo -n "Sending sign-up message ..."
     78 taler-merchant-report-generator \
     79     -c "$CONF" \
     80     --test \
     81     -L INFO \
     82     2> report-generator-signup.log
     83 if [ ! -f "$MESSAGE" ]
     84 then
     85     cat report-generator-signup.log >&2
     86     exit_fail "No sign-up message was written to $MESSAGE"
     87 fi
     88 # The instance never set a notification language: the sign-up
     89 # message must be sent anyway.
     90 for EXPECTED in \
     91     "User name      : signup" \
     92     "Business name  : Signup & Sons" \
     93     "Log in at      : http://localhost:9966/"
     94 do
     95     if ! grep -qxF "$EXPECTED" "$MESSAGE"
     96     then
     97         cat "$MESSAGE" >&2
     98         exit_fail "Sign-up message lacks line '$EXPECTED'"
     99     fi
    100 done
    101 echo " OK"
    102 
    103 echo -n "Checking that the sign-up message is sent only once ..."
    104 rm -f "$MESSAGE"
    105 taler-merchant-report-generator \
    106     -c "$CONF" \
    107     --test \
    108     -L INFO \
    109     2> report-generator-signup-again.log
    110 if [ -f "$MESSAGE" ]
    111 then
    112     cat "$MESSAGE" >&2
    113     exit_fail "Sign-up message was sent again"
    114 fi
    115 echo " OK"
    116 
    117 echo "TEST PASSED"
    118 
    119 exit 0