This sort of test is known as a shibboleth. It relies on the overgeneralization and stereotyping of the way people speak in different regions. It especially focuses on specific characterizations of letter sounds and regional accents.
Using shibboleths, you can determine to a reasonable degree of accuracy whether a person is or is not from a certain area based on word sounds. Shibboleths are sometimes used in military operations to distinguish out spies and people from different areas that might be enemy territory. Throughout history, language has been used to sort people out into their regions for political purposes.
Each test used a phrase or series of phrases to listen for a difference in pronunciation. Say something wrong, and you might be in big trouble! The U.S. soldiers used shibboleths in the Second World War. In particular, during the Battle of Normandy, they used the phrase “flash, thunder, welcome” to make sure a person was a native English speaker.
A German speaker would pronounce welcome as “velcome”, therefore giving up the fact that he was the enemy. The British sometimes used the word “squirrel” to pick out Germans.