Your translation is quite right. The sentence seems to be a description of a function; which takes a function as the parameter, and its return value is a function too.
To be more precise, the first 为 means
（充当） serve as; act as; play the part of:
call a stag a horse;
This will serve as a proof.
The 2nd 为 means
（是） be; mean:
One kilometre is equivalent to two li.
One hundred centimetres make one metre.
为 in 汉语水平考试是一个考试为了外国人 (especially used as 为了) is used for describing the purpose.
work hard for realizing the four modernizations;
write for a living
BTW: The correct syntax should be 汉语水平考试是一个为了外国人的考试; because 为了外国人 is the modifier of 考试 so it should be put before of 考试 (i.e. the object). More naturally you can say 汉语水平考试是一个面向外国人的考试. Because 为了外国人 is broad and then might be confusing, the specific purpose is hard to get.