What is the ideal scenario for test and save buttons?
Another way of approaching this is instead of having two separate buttons for 'test' and 'save', is to incorporate the test connection into the save functionality. This way it becomes more of a validation process (the system prevents you from failing) rather than putting the burden on the user to ensure it works.
Should I allow connection to be saved without testing?
If you follow the above process, then that solves this problem. However, even if the consequence of saving a connection that fails is minimal, it is not user centto allow them to do something that will cause an error in the future.
How does it usually handled at backend and frontend?
This will depend almost entirely on your specific configuration/scenario, and will not be able to be answered here.