Skip to content

Commit

Permalink
Changes due to review
Browse files Browse the repository at this point in the history
  • Loading branch information
alallema committed Feb 23, 2022
1 parent 77294cb commit 7579c8f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
12 changes: 2 additions & 10 deletions meilisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,22 +504,14 @@ def generate_tenant_token(
if expires_at and expires_at < datetime.datetime.now():
raise Exception('The date expires_at should be in the future.')

api_key = str(self.config.api_key) if api_key is None else api_key

# Check if the api_key is not the master key
try:
client = Client(self.config.url, api_key)
client.get_keys()
raise Exception('The master key can be used to generated a token.')
except MeiliSearchError:
pass

# Standard JWT header for encryption with SHA256/HS256 algorithm
header = {
"typ": "JWT",
"alg": "HS256"
}

api_key = str(self.config.api_key) if api_key is None else api_key

# Add the required fields to the payload
payload = {
'apiKeyPrefix': api_key[0:8],
Expand Down
5 changes: 0 additions & 5 deletions tests/client/test_client_tenant_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ def test_generate_tenant_token_wit_empty_search_rules_in_dict(get_private_key):
with pytest.raises(Exception):
client.generate_tenant_token(search_rules={''})

def test_generate_tenant_token_with_master_key(client):
"""Tests create a tenant token with master key."""
with pytest.raises(Exception):
client.generate_tenant_token(search_rules=['*'])

def test_generate_tenant_token_with_bad_expires_at(client, get_private_key):
"""Tests create a tenant token with only search rules."""
client = meilisearch.Client(BASE_URL, get_private_key['key'])
Expand Down

0 comments on commit 7579c8f

Please sign in to comment.