In the 2009 film Star Trek, we see a young Kirk enter StarFleet Academy. A few years pass, and he takes the Kobayashi Maru test. Shortly afterwards, Nero attacks, and he ends up on the Enterprise. What rank (if any) was he at this point? Shortly afterwards, Pike promotes him, and through his cunning he manages to get promoted to Captain. I'd hope he wasn't just a rank-less cadet at the start of this, but the movie never makes it obvious.
When Chekov is trying to lock on to Kirk and Sulu (to beam them up) as they were falling from the black hole device, you can see on the screen that Chekov is using the names Lt, J. Kirk and Lt, H. Sulu. So I assume then that he was holding the rank of Lieutenant.
Obviously this raises another question about how quickly he went from Lieutenant to Captain (an extremely short period of time) but I suppose in wartime they did promote fast through 'battlefield promotions'. Maybe that's what happened to Kirk.
Kirk was a suspended cadet when the attack happens.
This was due to his questionable behavior regarding the Kobiyashi Maru test.
He was a cadet. Cadet is a rank in and of itself; the various cadet grades are usually not considered outside the cadet hierarchy.
That he was suspended doesn't change his rank (tho' he was apparently seconds away from being an ex-cadet).
We also do not know the canonical cadet grades, but, we presume to use the same system of cadet grades as the USNA at Anapolis does, he's a Cadet 1st Class (4th year cadet), possibly holding the positional grade of Cadet Lieutenant.
A Note on Midshipman
In the US, at least, a Midshipman is a Cadet or officer candidate in a naval officer training program, including the US Naval Academy at Annapolis and NROTC. It is also used for the cadets at the US Merchant Marine Academy. They hold authority just below that of a Chief Warrant Officer (W2), according to Naval manuals (such as Naval Orientation - Military manual for administrative purposes). Historically, there was a rank called "Passed Midshipman," but it was replaced with Ensign in the late 19th C.
Various non-canon sources (especially the various Role-playing games) make an artificial distinction between Midshipman and Cadet, with Cadets being in the 4 year undergraduate program, and Midshipmen being in later training prior to assignment as an Ensign or Lieutenant JG. This distinction was introduced to this author in FASA's Star Trek The Role-Playing Game, and may be based upon prior fanon; the use of Midshipman in Star Trek II The Wrath of Khan may have contributed to this.
Such a distinction would make Star Fleet less like the US Navy ranks-wise; A US Navy Midshipman is an academy cadet; upon completion of the undergraduate portion, they are commissioned as ensigns, exactly as USMA West Point cadets are graduated as Second Lieutenants. Post graduation schooling at the USNA does occur; attendees are not cadets nor midshipmen, retaining full commissioned rank, even as some privileges are suspended for persons assigned to take training.
In either case, Kirk was a 4th year, and the mode of address in the film is "Cadet," so by either mode for midshipman, Mr. Kirk was not one. Starfleet either doesn't use "Midshipman" during that era, or reserves it for some other use.