Skip to content

Commit

Permalink
Merge pull request #175 from lsst-sqre/tickets/DM-36642
Browse files Browse the repository at this point in the history
DM-36624: Only pass groups with GIDs to moneypenny
  • Loading branch information
rra authored Oct 24, 2022
2 parents d4037f3 + 48cc354 commit 87402aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/nublado2/provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ async def provision_homedir(self, spawner: Spawner) -> None:
base_url = self.nublado_config.base_url
token = self.nublado_config.gafaelfawr_token

# Only include groups with GIDs. Provisioning can't do anything with
# the ones that don't have GIDs, and currently the model doesn't allow
# them.
groups = [g for g in auth_state["groups"] if "id" in g]

# Start the provisioning request.
dossier = {
"username": spawner.user.name,
"uid": int(auth_state["uid"]),
"groups": auth_state["groups"],
"groups": groups,
}
provision_url = urljoin(base_url, "moneypenny/users")
session = await get_session()
Expand Down
23 changes: 23 additions & 0 deletions tests/provisioner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,26 @@ async def test_provision() -> None:
m.get(status_url, callback=handler, repeat=True)
m.get(wait_url, callback=handler)
await resource_manager.provisioner.provision_homedir(spawner)


@pytest.mark.asyncio
async def test_no_gids() -> None:
resource_manager = ResourceManager()
spawner = Mock(spec=Spawner)
spawner.user = Mock(spec=User)
spawner.user.name = "someuser"
auth_state = {
"uid": 1234,
"groups": [{"name": "foo"}],
}
spawner.user.get_auth_state.return_value = auth_state

commission_url = "https://data.example.com/moneypenny/users"
status_url = "https://data.example.com/moneypenny/users/someuser"
wait_url = "https://data.example.com/moneypenny/users/someuser/wait"
with aioresponses() as m:
handler = build_handler("someuser", 1234, [])
m.post(commission_url, callback=handler)
m.get(status_url, callback=handler, repeat=True)
m.get(wait_url, callback=handler)
await resource_manager.provisioner.provision_homedir(spawner)

0 comments on commit 87402aa

Please sign in to comment.