Why is China an ally with Pakistan knowing that Pakistan is harboring terrorists?
Pakistan is not harboring terrorists, look at the people who are living in Pakistan, some are still suffering terrorism and terrorist inside or outside.
BTW, according to China's foreign policy, China won't be allied with any other country. So China isn't an ally of Pakistan, China and Pakistan are friends, or rather China and Pakistan are brothers!
China and Pakistan can trust each other, the trust is described: 'higher than mountains, deeper than oceans, sweeter than honey, and stronger than steel.'
I don't know too much about the details, but I know Pakistan was one of the first countries to recognize PRC, Pakistan stood by China when the international background was very bad for China.
Pakistan has helped China a lot, and China has also helped Pakistan a lot later. In China, there is an old saying: 'A friend in need is a friend indeed.' Our Chinese people have a heavy emotional character in our hearts, no words can fully express our gratitude, so no matter how the current political situation changes, China and Pakistan will keep the friendship going on.
Wish China and Pakistan to be better and better!