File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ # Copyright 2022 Google LLC
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ import main
16+
17+
18+ def fake_validate (assertion ):
19+ if assertion == "Valid" :
20+ return "[email protected] " ,
"user0001" 21+ else :
22+ return None , None
23+
24+
25+ main .validate_assertion = fake_validate
26+
27+
28+ def test_home_page ():
29+ client = main .app .test_client ()
30+
31+ # Good request check
32+ r = client .get ("/" , headers = {"X-Goog-IAP-JWT-Assertion" : "Valid" })
33+ assert "[email protected] " in r .
text 34+
35+ # Missing header check
36+ r = client .get ("/" )
37+ assert "None" in r .text
38+
39+ # Bad header check
40+ r = client .get ("/" , headers = {"X-Goog-IAP-JWT-Assertion" : "Not Valid" })
41+ assert "None" in r .text
Original file line number Diff line number Diff line change 1+ pytest==7.1.2
Original file line number Diff line number Diff line change 1+ # Copyright 2022 Google LLC
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ import main
16+
17+
18+ def test_hello ():
19+ main .app .testing = True
20+ client = main .app .test_client ()
21+
22+ r = client .get ("/" )
23+ assert r .status_code == 200
24+ response_text = r .data .decode ("utf-8" )
25+ assert "Hello, world!" in response_text
You can’t perform that action at this time.
0 commit comments