ClimateMind / climatemind-backend

Your climate action is here 🌎 Our API is a source for learning how climate change personally affects you and the things you care about most. Additionally, it will teach a scientifically proven method for communicating to others that climate change is a personally relevant issue to inspire action.
https://contribute.climatemind.org/v/rest-api/
MIT License
18 stars 20 forks source link

Inconsistent Email Validation Between Postman API Testing and Application Interface. #507

Closed tomaszpochron closed 9 months ago

tomaszpochron commented 9 months ago

Hi,

My name is Tomasz Pochron, and I am a student at Jagiellonian University. I'm writing to report a discrepancy observed in email address validation within our project.

During a practical exercise in our software development class, we noticed that when testing our API through Postman, it accepts email addresses with trailing spaces. However, this is not the case with our application's user interface, which correctly rejects such inputs. This inconsistency was also observed during routine quality assurance testing.

Here is a screenshot illustrating the issue: Zrzut ekranu 2024-01-06 221022

We are keen to understand the reason behind this discrepancy and would greatly appreciate any insights or advice you could offer. This will not only help us resolve the current issue but also enhance our overall understanding of API development and testing.

Thank you for your time and assistance.

Best regards, Tomasz Pochron

rodriguesk commented 9 months ago

Hi Tomasz @tomaszpochron, thanks so much for trying out the Climate Mind backend API. Your question is a good one. We use T-SQL (transact SQL) for our backend SQL server and database. SQL Queries that search the TSQL databases for matches in a table will ignore trailing spaces. This is a behavior that is built into the TSQL server and SQL dialect.

Another separate thing to mention just to keep in mind is that we use SQL Alchemy as an intermediary. The SQL alchemy package acts as a bridge, allowing us to use python code to conduct SQL database interactions. This is why you will rarely see SQL code in our code base and why it’s harder to realize that the inconsistency you pointed out is a feature of SQL.

I believe this answers your question. Let us know! And if not let us know and we will do our best to help out. You can read more about this too at the following links:

https://m.youtube.com/watch?v=kf7yop2ik3M

https://bertwagner.com/posts/trailing-spaces-in-sql-server/

https://www.brentozar.com/archive/2017/04/surprising-behavior-trailing-spaces/

https://learn.microsoft.com/en-US/sql/t-sql/language-elements/string-comparison-assignment?view=sql-server-ver16

Cheers, Kameron

On Sun, Jan 7, 2024 at 4:15 PM Tomasz Pochroń @.***> wrote:

External Email

Hi,

My name is Tomasz Pochron, and I am a student at Jagiellonian University. I'm writing to report a discrepancy observed in email address validation within our project.

During a practical exercise in our software development class, we noticed that when testing our API through Postman, it accepts email addresses with trailing spaces. However, this is not the case with our application's user interface, which correctly rejects such inputs. This inconsistency was also observed during routine quality assurance testing.

Here is a screenshot illustrating the issue: Zrzut.ekranu.2024-01-06.221022.png (view on web) https://github.com/ClimateMind/climatemind-backend/assets/23237107/8fc84f42-e6ce-4640-93c8-5c58daa2a772

We are keen to understand the reason behind this discrepancy and would greatly appreciate any insights or advice you could offer. This will not only help us resolve the current issue but also enhance our overall understanding of API development and testing.

Thank you for your time and assistance.

Best regards, Tomasz Pochron

— Reply to this email directly, view it on GitHub https://github.com/ClimateMind/climatemind-backend/issues/507, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEXL62VL76TIKTHHXPB5EETYNM3BNAVCNFSM6AAAAABBQV527GVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3DSMZWHEZTQMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

rodriguesk commented 9 months ago

@tomaszpochron I believe this behavior of ignoring trailing spaces is controlled by the ANSI_PADDING setting for the SQL server. By default is is set to ON. Turing it to OFF might resolve the inconsistency you brought up, but it creates other problems with the database so it’s recommended to keep it set to ON. https://learn.microsoft.com/en-US/sql/t-sql/statements/set-ansi-padding-transact-sql?view=sql-server-ver16

tomaszpochron commented 9 months ago

Hi Kameron (@rodriguesk),

Thank you so much for the detailed response regarding the trailing spaces issue in the Climate Mind backend API. Your explanation regarding the behavior of T-SQL and its interaction with SQL Alchemy provided a clear understanding of the issue. I appreciate the time and effort you took to address our query.

Best regards, Tomasz Pochron