Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whose responsibility is it to check data validity?

I am confused as to whether it is the caller or the callee's responsibility to check for data legality.

Should the callee check whether passed-in arguments should not be null and meet some other requirements so that the callee method can execute normally and successfully, and to catch any potential exceptions? Or it is the caller's responsibility to do this?

like image 524
hiway Avatar asked Jun 19 '13 09:06

hiway


People also ask

How do you test data validation?

Steps to Adopt Data Validation TestingData accuracy and data completeness tests ensure the data is correct. Data transformation tests verify that the data is not corrupted after transformation. Data quality tests then handle the bad data. Database comparison tests compare the source and target database.

What is data validation and how can we achieve it?

Data validation is a method for checking the accuracy and quality of your data, typically performed prior to importing and processing. It can also be considered a form of data cleansing.


1 Answers

Both consumer side(client) and provider side(API) validation.

Clients should do it because it means a better experience. For example, why do a network round trip just to be told that you've got one bad text field?

Providers should do it because they should never trust clients (e.g. XSS and man in the middle attacks). How do you know the request wasn't intercepted? Validate everything.

There are several levels of valid:

  1. All required fields present, correct formats. This is what the client validates.
  2. # 1 plus valid relationships between fields (e.g. if X is present then Y is required).
  3. # 1 plus # 2 plus business valid: meets all business rules for proper processing.

Only the provider side can do #2 and #3.

like image 199
duffymo Avatar answered Oct 19 '22 08:10

duffymo