twilio_sendsms fails with an http base URL: QSYS2 basicAuth option requires HTTPS

Abierto Apto para principiantes
#54 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
75/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
sql
Área
backend

Línea de trabajo

Empieza con src/twilio/publish.sql y sus opciones HTTP de twilio_sendsms; después, lee la documentación de la URL base en src/twilio/utils.sql. Usa el entorno de pruebas de IBM i 7.5 mencionado en #47 para comprobar que el servidor simulado recibe las credenciales Basic esperadas y que la función devuelve queued; confirma que la documentación advierte contra el uso de HTTP sin cifrar fuera de las pruebas locales.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

twilio_sendsms can't call an http base URL, such as a local test server. Every call fails:

SQL0443 ... HTTP_POST_VERBOSE ... BASICAUTH REQUIRES HTTPS (SQLSTATE 38501)

Cause

twilio_sendsms passes the credentials with QSYS2's basicAuth HTTP option, which IBM i only allows over HTTPS. The default Twilio URL is HTTPS, so this only shows up with a non-default base URL. #47 makes that possible by adding twilio_getbaseurl and its setters, so the toolkit can be pointed at a mock server for testing.

Fix

Build the Authorization: Basic header directly with systools.base64encode instead of using the basicAuth option. The twilio_getbaseurl docs also gain a reminder to use https outside local testing, because the credentials are then sent as-is over plain HTTP. With the default HTTPS base URL, the request is unchanged.

This was verified on IBM i 7.5 with the test harness from #47 (TwilioSendTest: the mock received the expected Basic credentials, and twilio_sendsms returned queued). The change applies on top of #47, which adds twilio_getbaseurl:

diff --git a/src/twilio/publish.sql b/src/twilio/publish.sql
index ba2ca8f..f16485d 100644
--- a/src/twilio/publish.sql
+++ b/src/twilio/publish.sql
@@ -32,7 +32,13 @@ begin
   declare response_message Varchar(10000) CCSID 1208;
   declare response_code int default 500;
   
-  set http_options = json_object('basicAuth': dbsdk_v1.twilio_getsid() concat ',' concat dbsdk_v1.twilio_getauthtoken(), 'header': 'content-type,application/x-www-form-urlencoded');
+  -- The credentials are sent as an Authorization header rather than with the basicAuth option,
+  -- which QSYS2's HTTP functions only allow over HTTPS, so that a non-default base URL (such as a
+  -- local test server) can use plain HTTP. The default base URL is HTTPS.
+  set http_options = json_object('headers': json_object(
+    'Content-Type': 'application/x-www-form-urlencoded',
+    'Authorization': 'Basic ' concat systools.base64encode(
+      cast(dbsdk_v1.twilio_getsid() concat ':' concat dbsdk_v1.twilio_getauthtoken() as varchar(2001) ccsid 1208))));
   
   set fullUrl = dbsdk_v1.twilio_getbaseurl() concat '/2010-04-01/Accounts/' concat dbsdk_v1.twilio_getsid() concat '/Messages.json';
   set payload = 'To=' concat to_cell_number concat
diff --git a/src/twilio/utils.sql b/src/twilio/utils.sql
index 5a54eef..617968f 100644
--- a/src/twilio/utils.sql
+++ b/src/twilio/utils.sql
@@ -136,7 +136,8 @@ end;
 -- changed, for example to route requests through a proxy or to a mock server for testing. The value
 -- used is the first one that is set: the function argument, then the job setting
 -- (`twilio_setbaseurlforjob`), then the user profile setting (`twilio_setbaseurlforme`), then the
--- default.
+-- default. `twilio_sendsms` sends the account SID and auth token with HTTP Basic authentication, so
+-- use an `https` base URL for anything other than local testing.
 --
 -- **Input parameters:**
 -- - `BASEURL` (optional): A base URL to return instead of the configured one.
Lenguaje dominante
RPGLE
Estrellas
13
Forks
7
Merge medio
1 d 10 h
PR fusionados (30 d)
4

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de IBM/AI-SQL-Toolkit-IBMi

Todos los issues de IBM/AI-SQL-Toolkit-IBMi

Issues similares

Más issues de Backend & API Design

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.