mirror of
https://github.com/simple-login/app.git
synced 2024-09-20 23:16:00 +08:00
Merge pull request #897 from simple-login/alias-option-endpoint
return whether a domain is custom or primary in GET /api/v5/alias/options
This commit is contained in:
commit
72464bd959
|
@ -90,7 +90,9 @@ def options_v5():
|
|||
suffixes: [
|
||||
{
|
||||
suffix: "suffix",
|
||||
signed_suffix: "signed_suffix"
|
||||
signed_suffix: "signed_suffix",
|
||||
is_custom: true,
|
||||
is_premium: false
|
||||
}
|
||||
]
|
||||
prefix_suggestion: str
|
||||
|
@ -141,7 +143,12 @@ def options_v5():
|
|||
|
||||
# custom domain should be put first
|
||||
ret["suffixes"] = [
|
||||
{"suffix": suffix.suffix, "signed_suffix": suffix.signed_suffix}
|
||||
{
|
||||
"suffix": suffix.suffix,
|
||||
"signed_suffix": suffix.signed_suffix,
|
||||
"is_custom": suffix.is_custom,
|
||||
"is_premium": suffix.is_premium,
|
||||
}
|
||||
for suffix in suffixes
|
||||
]
|
||||
|
||||
|
|
15
docs/api.md
15
docs/api.md
|
@ -231,7 +231,8 @@ Input:
|
|||
Output: a json with the following field:
|
||||
|
||||
- can_create: boolean. Whether user can create new alias
|
||||
- suffixes: list of dictionary with `suffix` and `signed-suffix`. List of alias `suffix` that user can use.
|
||||
- suffixes: list of alias suffix that user can use.
|
||||
Each item is a dictionary with `suffix`, `signed-suffix`, `is_custom`, `is_premium` as keys.
|
||||
The `signed-suffix` is necessary to avoid request tampering.
|
||||
- prefix_suggestion: string. Suggestion for the `alias prefix`. Usually this is the website name extracted
|
||||
from `hostname`. If no `hostname`, then the `prefix_suggestion` is empty.
|
||||
|
@ -248,15 +249,21 @@ For ex:
|
|||
"suffixes": [
|
||||
{
|
||||
"signed_suffix": ".cat@d1.test.X6_7OQ.0e9NbZHE_bQvuAapT6NdBml9m6Q",
|
||||
"suffix": ".cat@d1.test"
|
||||
"suffix": ".cat@d1.test",
|
||||
"is_custom": true,
|
||||
"is_premium": false
|
||||
},
|
||||
{
|
||||
"signed_suffix": ".chat@d2.test.X6_7OQ.TTgCrfqPj7UmlY723YsDTHhkess",
|
||||
"suffix": ".chat@d2.test"
|
||||
"suffix": ".chat@d2.test",
|
||||
"is_custom": false,
|
||||
"is_premium": false
|
||||
},
|
||||
{
|
||||
"signed_suffix": ".yeah@sl.local.X6_7OQ.i8XL4xsMsn7dxDEWU8eF-Zap0qo",
|
||||
"suffix": ".yeah@sl.local"
|
||||
"suffix": ".yeah@sl.local",
|
||||
"is_custom": true,
|
||||
"is_premium": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ from flask import url_for
|
|||
|
||||
from app.db import Session
|
||||
from app.models import User, ApiKey, AliasUsedOn, Alias
|
||||
from tests.utils import login
|
||||
|
||||
|
||||
def test_different_scenarios_v4(flask_client):
|
||||
|
@ -98,19 +99,10 @@ def test_different_scenarios_v4_2(flask_client):
|
|||
|
||||
|
||||
def test_different_scenarios_v5(flask_client):
|
||||
user = User.create(
|
||||
email="a@b.c", password="password", name="Test User", activated=True
|
||||
)
|
||||
Session.commit()
|
||||
|
||||
# create api_key
|
||||
api_key = ApiKey.create(user.id, "for test")
|
||||
Session.commit()
|
||||
user = login(flask_client)
|
||||
|
||||
# <<< without hostname >>>
|
||||
r = flask_client.get(
|
||||
"/api/v5/alias/options", headers={"Authentication": api_key.code}
|
||||
)
|
||||
r = flask_client.get("/api/v5/alias/options")
|
||||
|
||||
assert r.status_code == 200
|
||||
|
||||
|
@ -124,19 +116,15 @@ def test_different_scenarios_v5(flask_client):
|
|||
suffix_payload["signed_suffix"],
|
||||
)
|
||||
assert signed_suffix.startswith(suffix)
|
||||
assert "is_custom" in suffix_payload
|
||||
assert "is_premium" in suffix_payload
|
||||
|
||||
# <<< with hostname >>>
|
||||
r = flask_client.get(
|
||||
"/api/v5/alias/options?hostname=www.test.com",
|
||||
headers={"Authentication": api_key.code},
|
||||
)
|
||||
r = flask_client.get("/api/v5/alias/options?hostname=www.test.com")
|
||||
assert r.json["prefix_suggestion"] == "test"
|
||||
|
||||
# <<< with hostname with 2 parts TLD, for example wwww.numberoneshoes.co.nz >>>
|
||||
r = flask_client.get(
|
||||
"/api/v5/alias/options?hostname=wwww.numberoneshoes.co.nz",
|
||||
headers={"Authentication": api_key.code},
|
||||
)
|
||||
r = flask_client.get("/api/v5/alias/options?hostname=wwww.numberoneshoes.co.nz")
|
||||
assert r.json["prefix_suggestion"] == "numberoneshoes"
|
||||
|
||||
# <<< with recommendation >>>
|
||||
|
@ -147,9 +135,6 @@ def test_different_scenarios_v5(flask_client):
|
|||
)
|
||||
Session.commit()
|
||||
|
||||
r = flask_client.get(
|
||||
url_for("api.options_v4", hostname="www.test.com"),
|
||||
headers={"Authentication": api_key.code},
|
||||
)
|
||||
r = flask_client.get(url_for("api.options_v4", hostname="www.test.com"))
|
||||
assert r.json["recommendation"]["alias"] == alias.email
|
||||
assert r.json["recommendation"]["hostname"] == "www.test.com"
|
||||
|
|
|
@ -25,9 +25,9 @@ AWS_ACCESS_KEY_ID=to_fill
|
|||
AWS_SECRET_ACCESS_KEY=to_fill
|
||||
|
||||
# Paddle
|
||||
PADDLE_VENDOR_ID = 1
|
||||
PADDLE_MONTHLY_PRODUCT_ID = 2
|
||||
PADDLE_YEARLY_PRODUCT_ID = 3
|
||||
PADDLE_VENDOR_ID=1
|
||||
PADDLE_MONTHLY_PRODUCT_ID=2
|
||||
PADDLE_YEARLY_PRODUCT_ID=3
|
||||
PADDLE_PUBLIC_KEY_PATH=local_data/paddle.key.pub
|
||||
|
||||
# OpenId key
|
||||
|
|
Loading…
Reference in a new issue