Implement CHIS session validation
This commit is contained in:
@@ -150,3 +150,51 @@ def test_login_client_accepts_plain_host_config():
|
||||
|
||||
assert client.base_url == "http://chis.example.test:9002/chis"
|
||||
assert client.host == "chis.example.test:9002"
|
||||
|
||||
|
||||
def test_get_lander_info_uses_existing_cookie_to_query_account_info():
|
||||
transport = FakeTransport(
|
||||
[
|
||||
(
|
||||
{
|
||||
"code": 200,
|
||||
"body": {"userId": "u001", "userName": "doctor"},
|
||||
"msg": "success",
|
||||
},
|
||||
{},
|
||||
),
|
||||
]
|
||||
)
|
||||
client = ChisLoginClient(
|
||||
base_url="http://chis.example.test/chis",
|
||||
public_key="public-key",
|
||||
transport=transport,
|
||||
encrypt=fake_encrypt,
|
||||
)
|
||||
|
||||
result = client.get_lander_info("JSESSIONID=abc123; sessionId1=abc123")
|
||||
|
||||
assert result["body"]["userId"] == "u001"
|
||||
assert transport.calls[0]["url"] == "http://chis.example.test/chis/*.jsonRequest?"
|
||||
assert transport.calls[0]["headers"]["Cookie"] == "JSESSIONID=abc123; sessionId1=abc123"
|
||||
assert transport.calls[0]["payload"] == {
|
||||
"serviceId": "chis.myPageService",
|
||||
"serviceAction": "getLanderInfo",
|
||||
"method": "execute",
|
||||
}
|
||||
|
||||
|
||||
def test_get_lander_info_raises_session_invalid_when_chis_rejects_cookie():
|
||||
transport = FakeTransport([({"code": 403, "msg": "not login"}, {})])
|
||||
client = ChisLoginClient(
|
||||
base_url="http://chis.example.test/chis",
|
||||
public_key="public-key",
|
||||
transport=transport,
|
||||
encrypt=fake_encrypt,
|
||||
)
|
||||
|
||||
with pytest.raises(ChisLoginError) as exc_info:
|
||||
client.get_lander_info("JSESSIONID=expired")
|
||||
|
||||
assert exc_info.value.code == "chis_session_invalid"
|
||||
assert "not login" in str(exc_info.value)
|
||||
|
||||
Reference in New Issue
Block a user