O.T., you are absolutely correct, the foam itself will not hold moisture, but if you butt it up against plywood, which will, plus the vibration of the vehicle, say after 15000 miles on midwestern interstate I am sure it will not be perfectly sealed. Plus the foam won't rust, but it will also not let the water evaporate once it is trapped between the foam and the steel.
Try that same test with a steel divot, with the foam on it with a small penetration so the moisture can get to the metal. You'll see what I meant.
Please don't think I'm "Nat'ting"
here. Just hate once you get all that work into it, you wind up with a hole in it.
Only my .02, but there are others who have experiences with it too.
I have never used expanding foam with metal. Only plumbing, doors and window installs in a house.