Three types of tests are possible. UNCONDITIONAL, conditional on either margin, or FISHER EXACT which conditions on both margins. These tests are explained.
PIDE App Ekt L06 Contingency Tables - Related lecture from another course
BE L10 Contingency Table - Computing p-values in contingency table via simulations. Fisher Exact test and variants, conditioning one oneor both margins OR UNCONDITIONAL.