The Soviet Union placed a 23mm autocannon in orbit as part of Salyut 3, a manned space station launched in June 1974:
https://en.wikipedia.org/wiki/Salyut_3#On-board_gun
Hard to be certain due to Cold War secrecy, but the consensus seems to be that they conducted several test-firings before the station was finally deorbited.