mirror of
https://github.com/pezkuwichain/pezkuwi-wallet-android.git
synced 2026-11-20 01:26:11 +00:00
Open .kurd sub-pages and a site's own 404; show a suspended name as suspended (#40)
* Open a .kurd page address typed with a path Tapping the address bar puts the page's full address in the search box, for example https://dks-news.kurd/kategori/ekonomi. The search only knew a bare name, and a .kurd address is never a web address or a search, so such input produced no result at all: the reader could not open, edit or reload any page below the home page. KurdName.parseAddress takes the name and the path, query and fragment after it (printable ASCII, no port or user info), and the .kurd row opens that page. The look-alike check still runs on the name; choosing the official name opens its home page, since the typed path belongs to the other site. * Show a .kurd site's own 404 page for a page it does not have A missing page was answered with 404 and an empty body. WebView replaces such a response with its own "Webpage not available" screen (ERR_HTTP_RESPONSE_CODE_FAILURE), as if the site could not be reached, although the gateway had proven the page absent from a site that loads. For the page's own document the server now serves the site's /404.html with status 404, as a web server does (dks.news ships one), and a line of text when the site has none. Missing images and scripts are answered as before. The fixture is a Kubo-built directory with index.html and 404.html. * Show a suspended .kurd name as suspended, and open nothing of it The register can now stop a name: the court for up to 30 days, the emergency council for 72 hours. The lookup reads Navnisan::Suspensions beside Names, at the same finalized block and through the same proof path, and applies the pallet's rule: a suspension of the name, or of a name it sits under as a subname, for the registration it was made against and not yet run out. A suspended name resolves to a new Suspended result however it was read, since a refusal needs no proof. The site server serves nothing (451) and the browser shows the existing notice with a pause icon, who stopped the name, until when, and the hash of the written reasons. Strings in English, Kurmanji and Turkish. A chain without the Suspensions item stores nothing there, so on today's runtime nothing changes.
This commit is contained in:
1 parent
cb74f8cde0
commit
f50ca479e0
24 files changed
+476
-21
No files matched your search
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- A .kurd name stopped by the court or the emergency council: a paused circle. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M12,2A10,10 0,1 1,12 22A10,10 0,1 1,12 2ZM10,8.5V15.5M14,8.5V15.5"
|
||||
android:strokeWidth="2"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round" />
|
||||
</vector>
|
||||
@@ -2142,6 +2142,14 @@
|
||||
<string name="dapp_kurd_open_anyway">Dîsa jî veke</string>
|
||||
<string name="dapp_kurd_not_registered_title">Navekî wiha tune ye</string>
|
||||
<string name="dapp_kurd_not_registered_message">%s ne tomarkirî ye, an jî dema wê qediyaye.</string>
|
||||
<string name="dapp_kurd_suspended_title">Ev nav hatiye rawestandin</string>
|
||||
<string name="dapp_kurd_suspended_court_message">Dîwanê ev nav heta %s rawestandiye. Heta wê demê malpera wê nayê vekirin.</string>
|
||||
<string name="dapp_kurd_suspended_emergency_message">Desteya awarte ev nav heta %s rawestandiye. Ev rawestandin bi xwe diqede; Dîwan dikare wê zûtir rake.</string>
|
||||
<string name="dapp_kurd_suspended_by">Biryar</string>
|
||||
<string name="dapp_kurd_suspended_until">Heta</string>
|
||||
<string name="dapp_kurd_suspended_reason">Hincet</string>
|
||||
<string name="dapp_kurd_suspended_by_court">Dîwan</string>
|
||||
<string name="dapp_kurd_suspended_by_emergency">Desteya awarte</string>
|
||||
<string name="dapp_kurd_no_site_title">Li ser vî navî malper tune</string>
|
||||
<string name="dapp_kurd_no_site_message">Nav tomarkirî ye, lê xwediyê wê malperek ku cîzdan dikare veke belav nekiriye.</string>
|
||||
<string name="dapp_kurd_unavailable_title">Nehat barkirin</string>
|
||||
|
||||
@@ -2139,6 +2139,14 @@ Referral kısmına bu adresi yapıştır:
|
||||
<string name="dapp_kurd_open_anyway">Yine de aç</string>
|
||||
<string name="dapp_kurd_not_registered_title">Böyle bir ad yok</string>
|
||||
<string name="dapp_kurd_not_registered_message">%s kayıtlı değil ya da kaydının süresi doldu.</string>
|
||||
<string name="dapp_kurd_suspended_title">Bu ad askıya alındı</string>
|
||||
<string name="dapp_kurd_suspended_court_message">Dîwan bu adı %s tarihine kadar askıya aldı. O zamana kadar sitesi açılamaz.</string>
|
||||
<string name="dapp_kurd_suspended_emergency_message">Acil kurul bu adı %s tarihine kadar askıya aldı. Askı kendiliğinden biter; Dîwan daha önce kaldırabilir.</string>
|
||||
<string name="dapp_kurd_suspended_by">Karar</string>
|
||||
<string name="dapp_kurd_suspended_until">Bitiş</string>
|
||||
<string name="dapp_kurd_suspended_reason">Gerekçe</string>
|
||||
<string name="dapp_kurd_suspended_by_court">Dîwan</string>
|
||||
<string name="dapp_kurd_suspended_by_emergency">Acil kurul</string>
|
||||
<string name="dapp_kurd_no_site_title">Bu adda site yok</string>
|
||||
<string name="dapp_kurd_no_site_message">Ad kayıtlı, ama sahibi cüzdanın açabileceği bir site yayımlamamış.</string>
|
||||
<string name="dapp_kurd_unavailable_title">Yüklenemedi</string>
|
||||
|
||||
@@ -2867,6 +2867,14 @@
|
||||
<string name="dapp_kurd_open_anyway">Open anyway</string>
|
||||
<string name="dapp_kurd_not_registered_title">No such name</string>
|
||||
<string name="dapp_kurd_not_registered_message">%s is not registered, or its registration has ended.</string>
|
||||
<string name="dapp_kurd_suspended_title">This name is suspended</string>
|
||||
<string name="dapp_kurd_suspended_court_message">The Dîwan has suspended this name until %s. Its site cannot be opened until then.</string>
|
||||
<string name="dapp_kurd_suspended_emergency_message">The emergency council has suspended this name until %s. It ends by itself; the Dîwan can lift it sooner.</string>
|
||||
<string name="dapp_kurd_suspended_by">Decided by</string>
|
||||
<string name="dapp_kurd_suspended_until">Until</string>
|
||||
<string name="dapp_kurd_suspended_reason">Reasons</string>
|
||||
<string name="dapp_kurd_suspended_by_court">Dîwan</string>
|
||||
<string name="dapp_kurd_suspended_by_emergency">Emergency council</string>
|
||||
<string name="dapp_kurd_no_site_title">No site at this name</string>
|
||||
<string name="dapp_kurd_no_site_message">The name is registered, but its owner has not published a site the wallet can open.</string>
|
||||
<string name="dapp_kurd_unavailable_title">Could not be loaded</string>
|
||||
|
||||
+6
-3
@@ -12,11 +12,14 @@ sealed interface DappSearchResult {
|
||||
override val isTrustedByNova: Boolean = false
|
||||
}
|
||||
|
||||
/** A `.kurd` name: resolved on chain when opened, never looked up on the web. */
|
||||
class KurdName(val name: io.novafoundation.nova.runtime.names.KurdName) : DappSearchResult {
|
||||
/** A page under a `.kurd` name: resolved on chain when opened, never looked up on the web. */
|
||||
class KurdName(
|
||||
val name: io.novafoundation.nova.runtime.names.KurdName,
|
||||
val path: String = "/"
|
||||
) : DappSearchResult {
|
||||
override val isTrustedByNova: Boolean = true
|
||||
|
||||
val url: String get() = "https://${name.name}/"
|
||||
val url: String get() = "https://${name.name}$path"
|
||||
}
|
||||
|
||||
class Dapp(val dapp: DApp) : DappSearchResult {
|
||||
|
||||
+3
-3
@@ -34,7 +34,7 @@ class SearchDappInteractor(
|
||||
.map(DappSearchResult::Dapp)
|
||||
|
||||
// A .kurd name is resolved on chain by the wallet: never a web address, never a search query
|
||||
val kurdName = KurdName.parse(query).takeIf { KurdName.mentionsKurd(query) }
|
||||
val kurdAddress = KurdName.parseAddress(query).takeIf { KurdName.mentionsKurd(query) }
|
||||
|
||||
val searchGroupContent = when {
|
||||
query.isEmpty() -> null
|
||||
@@ -50,8 +50,8 @@ class SearchDappInteractor(
|
||||
}
|
||||
|
||||
buildMap {
|
||||
kurdName?.let {
|
||||
put(DappSearchGroup.KURD_NAME, listOf(DappSearchResult.KurdName(it)))
|
||||
kurdAddress?.let { (name, path) ->
|
||||
put(DappSearchGroup.KURD_NAME, listOf(DappSearchResult.KurdName(name, path)))
|
||||
}
|
||||
|
||||
searchGroupContent?.let {
|
||||
|
||||
+34
@@ -26,6 +26,7 @@ import io.novafoundation.nova.common.utils.insets.applyNavigationBarInsets
|
||||
import io.novafoundation.nova.common.utils.insets.applyStatusBarInsets
|
||||
import io.novafoundation.nova.common.utils.makeGone
|
||||
import io.novafoundation.nova.common.utils.makeVisible
|
||||
import io.novafoundation.nova.common.utils.formatting.formatDateTime
|
||||
import io.novafoundation.nova.common.utils.setImageTintRes
|
||||
import io.novafoundation.nova.common.utils.setVisible
|
||||
import io.novafoundation.nova.common.utils.webView.WebViewRequestInterceptor
|
||||
@@ -51,6 +52,7 @@ import io.novafoundation.nova.feature_dapp_impl.web3.webview.Web3WebViewClient
|
||||
import io.novafoundation.nova.feature_dapp_impl.web3.webview.WebViewHolder
|
||||
import io.novafoundation.nova.feature_external_sign_api.presentation.externalSign.AuthorizeDappBottomSheet
|
||||
import io.novafoundation.nova.runtime.names.KurdName
|
||||
import io.novafoundation.nova.runtime.names.NameSuspension
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -445,6 +447,22 @@ class DAppBrowserFragment : BaseFragment<DAppBrowserViewModel, FragmentDappBrows
|
||||
R.string.dapp_kurd_back,
|
||||
viewModel::kurdBack
|
||||
)
|
||||
KurdPageUi.NoticeKind.SUSPENDED -> {
|
||||
val suspension = requireNotNull(page.suspension) { "A suspended notice without its suspension" }
|
||||
val until = suspension.until.formatDateTime()
|
||||
val message = when (suspension.by) {
|
||||
NameSuspension.By.COURT -> R.string.dapp_kurd_suspended_court_message
|
||||
NameSuspension.By.EMERGENCY -> R.string.dapp_kurd_suspended_emergency_message
|
||||
}
|
||||
Look(
|
||||
R.drawable.ic_kurd_suspended,
|
||||
R.color.icon_negative,
|
||||
R.string.dapp_kurd_suspended_title,
|
||||
getString(message, until),
|
||||
R.string.dapp_kurd_back,
|
||||
viewModel::kurdBack
|
||||
)
|
||||
}
|
||||
KurdPageUi.NoticeKind.NO_SITE -> Look(
|
||||
R.drawable.ic_info,
|
||||
R.color.icon_secondary,
|
||||
@@ -471,9 +489,25 @@ class DAppBrowserFragment : BaseFragment<DAppBrowserViewModel, FragmentDappBrows
|
||||
notice.kurdNoticePrimary.setText(look.primary)
|
||||
notice.kurdNoticePrimary.setOnClickListener { look.primaryAction() }
|
||||
notice.kurdNoticeSecondary.setVisible(kind == KurdPageUi.NoticeKind.NEEDS_CONSENT)
|
||||
showKurdSuspension(page.suspension.takeIf { kind == KurdPageUi.NoticeKind.SUSPENDED })
|
||||
notice.kurdNoticeSecondary.setText(R.string.dapp_kurd_open_anyway)
|
||||
}
|
||||
|
||||
private fun showKurdSuspension(suspension: NameSuspension?) {
|
||||
val details = binder.dappBrowserKurdNotice
|
||||
details.kurdNoticeSuspension.setVisible(suspension != null)
|
||||
if (suspension == null) return
|
||||
|
||||
details.kurdNoticeSuspensionBy.setText(
|
||||
when (suspension.by) {
|
||||
NameSuspension.By.COURT -> R.string.dapp_kurd_suspended_by_court
|
||||
NameSuspension.By.EMERGENCY -> R.string.dapp_kurd_suspended_by_emergency
|
||||
}
|
||||
)
|
||||
details.kurdNoticeSuspensionUntil.text = suspension.until.formatDateTime()
|
||||
details.kurdNoticeSuspensionReason.text = suspension.reason.let { "${it.take(6)}…${it.takeLast(4)}" }
|
||||
}
|
||||
|
||||
/** Storage, cookies and permissions the page kept under its name; then it loads afresh. */
|
||||
private fun clearKurdSiteData(name: KurdName) {
|
||||
val origin = "https://${name.name}"
|
||||
|
||||
+5
-2
@@ -2,6 +2,7 @@ package io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.kurd
|
||||
|
||||
import io.novafoundation.nova.runtime.names.KurdName
|
||||
import io.novafoundation.nova.runtime.names.NameRecord
|
||||
import io.novafoundation.nova.runtime.names.NameSuspension
|
||||
import io.novafoundation.nova.runtime.names.content.KurdSiteServer.PageState
|
||||
import java.net.URI
|
||||
|
||||
@@ -13,7 +14,8 @@ sealed interface KurdPageUi {
|
||||
/** [onChainVersion]: a feed showing the release the chain names, as no newer one could be confirmed. */
|
||||
class Open(override val name: KurdName, val badge: Badge, val details: Details, val onChainVersion: Boolean = false) : KurdPageUi
|
||||
|
||||
class Notice(override val name: KurdName, val kind: NoticeKind) : KurdPageUi
|
||||
/** [suspension]: who stopped the name and until when, for [NoticeKind.SUSPENDED]. */
|
||||
class Notice(override val name: KurdName, val kind: NoticeKind, val suspension: NameSuspension? = null) : KurdPageUi
|
||||
|
||||
enum class Badge {
|
||||
/** Granted by Parliament, or under such a name: the state's own. */
|
||||
@@ -26,7 +28,7 @@ sealed interface KurdPageUi {
|
||||
UNVERIFIED,
|
||||
}
|
||||
|
||||
enum class NoticeKind { REFUSED, NEEDS_CONSENT, NOT_REGISTERED, NO_SITE, UNAVAILABLE }
|
||||
enum class NoticeKind { REFUSED, NEEDS_CONSENT, NOT_REGISTERED, SUSPENDED, NO_SITE, UNAVAILABLE }
|
||||
|
||||
class Details(
|
||||
val badge: Badge,
|
||||
@@ -72,6 +74,7 @@ sealed interface KurdPageUi {
|
||||
is PageState.NeedsConsent -> Notice(name, NoticeKind.NEEDS_CONSENT)
|
||||
PageState.Refused -> Notice(name, NoticeKind.REFUSED)
|
||||
PageState.NotRegistered -> Notice(name, NoticeKind.NOT_REGISTERED)
|
||||
is PageState.Suspended -> Notice(name, NoticeKind.SUSPENDED, state.suspension)
|
||||
PageState.NoSite -> Notice(name, NoticeKind.NO_SITE)
|
||||
PageState.Unavailable -> Notice(name, NoticeKind.UNAVAILABLE)
|
||||
}
|
||||
|
||||
+8
-8
@@ -23,7 +23,6 @@ import io.novafoundation.nova.feature_dapp_impl.presentation.DAppRouter
|
||||
import io.novafoundation.nova.feature_dapp_impl.presentation.common.dappCategoryToUi
|
||||
import io.novafoundation.nova.feature_dapp_impl.presentation.search.model.DappSearchModel
|
||||
import io.novafoundation.nova.runtime.names.KurdLookalikes
|
||||
import io.novafoundation.nova.runtime.names.KurdName
|
||||
import io.novafoundation.nova.runtime.names.KurdNameResolver
|
||||
import io.novafoundation.nova.runtime.names.KurdResolution
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
@@ -128,7 +127,7 @@ class DAppSearchViewModel(
|
||||
)
|
||||
|
||||
is DappSearchResult.KurdName -> DappSearchModel(
|
||||
title = searchResult.name.name,
|
||||
title = searchResult.name.name + searchResult.path.takeIf { it != "/" }.orEmpty(),
|
||||
description = resourceManager.getString(R.string.dapp_search_kurd_name_subtitle),
|
||||
iconRes = R.drawable.shield_checkmark_outline,
|
||||
searchResult = searchResult,
|
||||
@@ -143,7 +142,7 @@ class DAppSearchViewModel(
|
||||
is DappSearchResult.Dapp -> searchResult.dapp.url
|
||||
is DappSearchResult.Search -> searchResult.searchUrl
|
||||
is DappSearchResult.Url -> searchResult.url
|
||||
is DappSearchResult.KurdName -> urlAfterLookalikeCheck(searchResult.name)
|
||||
is DappSearchResult.KurdName -> urlAfterLookalikeCheck(searchResult)
|
||||
}
|
||||
|
||||
if (!searchResult.isTrustedByNova) {
|
||||
@@ -166,17 +165,18 @@ class DAppSearchViewModel(
|
||||
* chooses that one. Looked up only when the typed name has such a candidate, and for a few
|
||||
* seconds at most: the opened page still shows by its badge whether it is official.
|
||||
*/
|
||||
private suspend fun urlAfterLookalikeCheck(typed: KurdName): String {
|
||||
private suspend fun urlAfterLookalikeCheck(typed: DappSearchResult.KurdName): String {
|
||||
val official = withTimeoutOrNull(LOOKALIKE_CHECK_MILLIS) {
|
||||
KurdLookalikes.candidates(typed).firstOrNull { candidate ->
|
||||
KurdLookalikes.candidates(typed.name).firstOrNull { candidate ->
|
||||
val resolution = kurdNameResolver.resolve(candidate)
|
||||
resolution is KurdResolution.Resolved && resolution.verified && resolution.official
|
||||
}
|
||||
} ?: return DappSearchResult.KurdName(typed).url
|
||||
} ?: return typed.url
|
||||
|
||||
return when (kurdLookalikeWarning.awaitAction(KurdLookalikeWarning(typed, official))) {
|
||||
return when (kurdLookalikeWarning.awaitAction(KurdLookalikeWarning(typed.name, official))) {
|
||||
// The official site's home page: the typed path belongs to a different site
|
||||
KurdLookalikeChoice.GO_OFFICIAL -> DappSearchResult.KurdName(official).url
|
||||
KurdLookalikeChoice.OPEN_TYPED -> DappSearchResult.KurdName(typed).url
|
||||
KurdLookalikeChoice.OPEN_TYPED -> typed.url
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,86 @@
|
||||
android:lineSpacingMultiplier="1.2"
|
||||
tools:text="@string/dapp_kurd_refused_message" />
|
||||
|
||||
<!-- Who stopped the name, until when, and the hash of their written reasons (D23) -->
|
||||
<LinearLayout
|
||||
android:id="@+id/kurdNoticeSuspension"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="18dp"
|
||||
android:background="@drawable/bg_block_12"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="14dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
style="@style/TextAppearance.NovaFoundation.Regular.Caption1.Secondary"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dapp_kurd_suspended_by" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/kurdNoticeSuspensionBy"
|
||||
style="@style/TextAppearance.NovaFoundation.Regular.Caption1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textColor="@color/text_primary" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="8dp">
|
||||
|
||||
<TextView
|
||||
style="@style/TextAppearance.NovaFoundation.Regular.Caption1.Secondary"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dapp_kurd_suspended_until" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/kurdNoticeSuspensionUntil"
|
||||
style="@style/TextAppearance.NovaFoundation.Regular.Caption1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textColor="@color/text_primary" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="8dp">
|
||||
|
||||
<TextView
|
||||
style="@style/TextAppearance.NovaFoundation.Regular.Caption1.Secondary"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dapp_kurd_suspended_reason" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/kurdNoticeSuspensionReason"
|
||||
style="@style/TextAppearance.NovaFoundation.Regular.Caption1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textColor="@color/text_primary"
|
||||
android:fontFamily="monospace" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<io.novafoundation.nova.common.view.PrimaryButton
|
||||
android:id="@+id/kurdNoticePrimary"
|
||||
style="@style/Widget.Nova.Button.Primary"
|
||||
|
||||
+7
@@ -37,6 +37,13 @@ class SearchDappInteractorTest {
|
||||
assertEquals("https://serok.gov.kurd/", (offered as DappSearchResult.KurdName).url)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a kurd page address is offered with its path`() = runBlocking {
|
||||
val offered = interactor.searchDapps("https://dks-news.kurd/a/missing", categoryId = null)[DappSearchGroup.KURD_NAME]!!.single()
|
||||
|
||||
assertEquals("https://dks-news.kurd/a/missing", (offered as DappSearchResult.KurdName).url)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an invalid kurd name is offered nowhere`() = runBlocking {
|
||||
listOf("uni-x--edu.kurd", "dks_news.kurd", "a.b.c.d.e.kurd").forEach { query ->
|
||||
|
||||
+10
@@ -4,6 +4,7 @@ import io.novafoundation.nova.runtime.names.KurdName
|
||||
import io.novafoundation.nova.runtime.names.KurdResolution
|
||||
import io.novafoundation.nova.runtime.names.NameRecord
|
||||
import io.novafoundation.nova.runtime.names.NameStatus
|
||||
import io.novafoundation.nova.runtime.names.NameSuspension
|
||||
import io.novafoundation.nova.runtime.names.content.Cid
|
||||
import io.novafoundation.nova.runtime.names.content.KurdSiteServer.PageState
|
||||
import org.junit.Assert.assertEquals
|
||||
@@ -51,6 +52,15 @@ class KurdPageUiTest {
|
||||
assertNull(KurdPageUi.from(name, null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a suspended name is a notice that carries who stopped it and until when`() {
|
||||
val suspension = NameSuspension(until = 1_800_000_000_000, reg = 1, reason = "0x00", by = NameSuspension.By.EMERGENCY)
|
||||
val notice = KurdPageUi.from(name, PageState.Suspended(suspension)) as KurdPageUi.Notice
|
||||
|
||||
assertEquals(KurdPageUi.NoticeKind.SUSPENDED, notice.kind)
|
||||
assertEquals(suspension, notice.suspension)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a feed showing the chain's version says so`() {
|
||||
val resolution = KurdResolution.Resolved(name, leased(), NameStatus.ACTIVE, verified = true)
|
||||
|
||||
@@ -78,6 +78,28 @@ class KurdName private constructor(
|
||||
return KurdName(labels)
|
||||
}
|
||||
|
||||
/**
|
||||
* A `.kurd` page address -- the name and the path, query and fragment after it, as the address
|
||||
* bar shows and the reader edits it -- or null when the name is invalid ([parse]) or what follows
|
||||
* it is not a plain URL path. The path is `/` when none is given.
|
||||
*/
|
||||
fun parseAddress(input: String): Pair<KurdName, String>? {
|
||||
var text = input.trim()
|
||||
if (text.startsWith("https://", ignoreCase = true)) text = text.substring("https://".length)
|
||||
val end = text.indexOfFirst { it in "/?#" }.takeIf { it >= 0 } ?: text.length
|
||||
val name = parse(text.substring(0, end)) ?: return null
|
||||
|
||||
val rest = text.substring(end)
|
||||
if (rest.isEmpty()) return name to "/"
|
||||
val path = if (rest.startsWith("/")) rest else "/$rest"
|
||||
// Printable ASCII only: the page is fetched by path, so nothing may hide in it
|
||||
if (path.any { it.code <= 0x20 || it.code >= 0x7f }) return null
|
||||
val uri = runCatching { java.net.URI("https://${name.name}$path") }.getOrNull() ?: return null
|
||||
if (uri.host != name.name || uri.port != -1 || uri.userInfo != null) return null
|
||||
|
||||
return name to path
|
||||
}
|
||||
|
||||
/** `a-z`, `0-9` and `-`, 1 to 63 bytes, no hyphen at either end and no `--` anywhere. */
|
||||
fun isValidLabel(label: String): Boolean {
|
||||
if (label.isEmpty() || label.length > MAX_LABEL) return false
|
||||
|
||||
@@ -131,12 +131,14 @@ class RealKurdNameResolver(
|
||||
companion object {
|
||||
|
||||
/**
|
||||
* D23: a suspended name opens nothing, read either way -- a refusal needs no proof.
|
||||
* D18: a proven answer stands; an unproven one opens only for a name nobody could take for an
|
||||
* institution's, and with a warning.
|
||||
*/
|
||||
internal fun judge(name: KurdName, lookup: NameLookup, verified: Boolean): KurdResolution = when (lookup) {
|
||||
NameLookup.NotFound, NameLookup.Lapsed -> KurdResolution.NotFound(name, verified)
|
||||
is NameLookup.Found -> when {
|
||||
lookup.suspension != null -> KurdResolution.Suspended(name, lookup.suspension, verified)
|
||||
verified -> KurdResolution.Resolved(name, lookup.record, lookup.status, verified = true, block = lookup.block)
|
||||
mustBeVerified(name, lookup) -> KurdResolution.Refused(name)
|
||||
else -> KurdResolution.Resolved(name, lookup.record, lookup.status, verified = false, block = lookup.block)
|
||||
|
||||
@@ -22,6 +22,12 @@ sealed interface KurdResolution {
|
||||
val official: Boolean get() = record.isOfficial
|
||||
}
|
||||
|
||||
/**
|
||||
* Stopped by the court or the emergency council (decision D23): the name and everything under
|
||||
* it open nothing until the suspension ends or is lifted, however it was read.
|
||||
*/
|
||||
class Suspended(override val name: KurdName, val suspension: NameSuspension, val verified: Boolean) : KurdResolution
|
||||
|
||||
/** Not registered, expired, or orphaned by its parent's re-registration. */
|
||||
class NotFound(override val name: KurdName, val verified: Boolean) : KurdResolution
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ sealed interface NameLookup {
|
||||
|
||||
/** Two sources agree when they return the same records byte for byte and judge them the same. */
|
||||
fun agreesWith(other: NameLookup): Boolean = when (this) {
|
||||
is Found -> other is Found && rawChain == other.rawChain && status == other.status && locked == other.locked
|
||||
is Found -> other is Found && rawChain == other.rawChain && status == other.status && locked == other.locked && suspension == other.suspension
|
||||
else -> this === other
|
||||
}
|
||||
|
||||
@@ -46,12 +46,15 @@ sealed interface NameLookup {
|
||||
val locked: Boolean,
|
||||
/** The finalized block it was read at, when the source said; not part of agreement. */
|
||||
val block: Long? = null,
|
||||
/** The suspension that stops the name now: its own, or a name's it sits under. */
|
||||
val suspension: NameSuspension? = null,
|
||||
) : NameLookup
|
||||
|
||||
companion object {
|
||||
|
||||
private val NAMES_PREFIX = "Navnisan".toByteArray().xxHash128() + "Names".toByteArray().xxHash128()
|
||||
private val LOCKED_PREFIX = "Navnisan".toByteArray().xxHash128() + "Locked".toByteArray().xxHash128()
|
||||
private val SUSPENSIONS_PREFIX = "Navnisan".toByteArray().xxHash128() + "Suspensions".toByteArray().xxHash128()
|
||||
private val TIMESTAMP_NOW = "Timestamp".toByteArray().xxHash128() + "Now".toByteArray().xxHash128()
|
||||
|
||||
/** `NavnisanGracePeriod`: 30 days after a lease ends the name still resolves (decision D11). */
|
||||
@@ -61,6 +64,8 @@ sealed interface NameLookup {
|
||||
|
||||
fun lockedKey(node: ByteArray) = LOCKED_PREFIX + node
|
||||
|
||||
fun suspensionsKey(node: ByteArray) = SUSPENSIONS_PREFIX + node
|
||||
|
||||
val timestampNowKey: ByteArray get() = TIMESTAMP_NOW.copyOf()
|
||||
|
||||
/**
|
||||
@@ -87,10 +92,30 @@ sealed interface NameLookup {
|
||||
|
||||
val status = effectiveStatus(records.map { it.first }, now) ?: return Lapsed
|
||||
val locked = nodes.any { reader.storage(lockedKey(it), at) != null }
|
||||
val suspension = suspension(reader, at, nodes, records.map { it.first }, now)
|
||||
|
||||
val block = runCatching { reader.blockNumber(at) }.getOrNull()
|
||||
|
||||
return Found(records.first().first, status, records.map { it.second }, locked, block)
|
||||
return Found(records.first().first, status, records.map { it.second }, locked, block, suspension)
|
||||
}
|
||||
|
||||
/**
|
||||
* `Pezpallet::is_suspended`: the name's own suspension, then each ancestor's while the name
|
||||
* below is a subname. A chain without `Suspensions` stores nothing there, and nothing is stopped.
|
||||
*/
|
||||
private suspend fun suspension(
|
||||
reader: NameStorageReader,
|
||||
at: String,
|
||||
nodes: List<ByteArray>,
|
||||
chain: List<NameRecord>,
|
||||
now: Long,
|
||||
): NameSuspension? {
|
||||
for (level in chain.indices) {
|
||||
val suspension = reader.storage(suspensionsKey(nodes[level]), at)?.let(NameSuspension::decode)
|
||||
if (suspension != null && suspension.holdsFor(chain[level], now)) return suspension
|
||||
if (chain[level].kind != NameRecord.Kind.SUB) return null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package io.novafoundation.nova.runtime.names
|
||||
|
||||
import io.novasama.substrate_sdk_android.extensions.toHexString
|
||||
|
||||
/**
|
||||
* `pezpallet_navnisan::Suspension`, decoded from the raw value of `Navnisan::Suspensions[node]`:
|
||||
* the court, or the emergency council, has stopped a name until [until] (decision D23). While it
|
||||
* holds the name and every name under it resolve to nothing.
|
||||
*/
|
||||
data class NameSuspension(
|
||||
/** Milliseconds, chain time; the suspension ends by itself then. */
|
||||
val until: Long,
|
||||
/** The registration suspended; a name registered anew is not. */
|
||||
val reg: Long,
|
||||
/** Hash of the written reasons, hex with `0x`. */
|
||||
val reason: String,
|
||||
val by: By,
|
||||
) {
|
||||
|
||||
enum class By { COURT, EMERGENCY }
|
||||
|
||||
/** `Pezpallet::suspension_of`: for this registration, and not yet run out. */
|
||||
fun holdsFor(record: NameRecord, now: Long): Boolean = reg == record.reg && now < until
|
||||
|
||||
companion object {
|
||||
|
||||
fun decode(bytes: ByteArray): NameSuspension {
|
||||
val reader = ScaleReader(bytes)
|
||||
val suspension = with(reader) {
|
||||
NameSuspension(
|
||||
until = u64().toLong(),
|
||||
reg = u64().toLong(),
|
||||
reason = bytes(32).toHexString(withPrefix = true),
|
||||
by = when (val index = u8()) {
|
||||
0 -> By.COURT
|
||||
1 -> By.EMERGENCY
|
||||
else -> error("Unknown suspension variant $index")
|
||||
},
|
||||
)
|
||||
}
|
||||
require(reader.isExhausted) { "Trailing bytes after a suspension" }
|
||||
|
||||
return suspension
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-3
@@ -4,6 +4,7 @@ import io.novafoundation.nova.runtime.names.KurdName
|
||||
import io.novafoundation.nova.runtime.names.KurdNameResolver
|
||||
import io.novafoundation.nova.runtime.names.KurdResolution
|
||||
import io.novafoundation.nova.runtime.names.NameRecord
|
||||
import io.novafoundation.nova.runtime.names.NameSuspension
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
@@ -50,6 +51,9 @@ class KurdSiteServer(
|
||||
|
||||
object NotRegistered : PageState
|
||||
|
||||
/** Stopped by the court or the emergency council; nothing of it is served. */
|
||||
class Suspended(val suspension: NameSuspension) : PageState
|
||||
|
||||
/** Registered, but no site: no content, or content of a kind this wallet does not serve. */
|
||||
object NoSite : PageState
|
||||
|
||||
@@ -81,15 +85,16 @@ class KurdSiteServer(
|
||||
val name = KurdName.parse(host) ?: return status(404, "Not Found")
|
||||
val segments = decodePath(encodedPath) ?: return status(400, "Bad Request")
|
||||
|
||||
val (state, response) = handle(name, segments)
|
||||
val (state, response) = handle(name, segments, mainFrame)
|
||||
if (mainFrame) _pageStates.update { it + (name to state) }
|
||||
return response
|
||||
}
|
||||
|
||||
private suspend fun handle(name: KurdName, segments: List<String>): Pair<PageState, Response> {
|
||||
private suspend fun handle(name: KurdName, segments: List<String>, mainFrame: Boolean): Pair<PageState, Response> {
|
||||
val resolution = when (val resolved = resolve(name)) {
|
||||
is KurdResolution.Resolved -> resolved
|
||||
is KurdResolution.NotFound -> return PageState.NotRegistered to status(404, "Not Found")
|
||||
is KurdResolution.Suspended -> return PageState.Suspended(resolved.suspension) to status(451, "Unavailable For Legal Reasons")
|
||||
is KurdResolution.Refused -> return PageState.Refused to status(403, "Forbidden")
|
||||
is KurdResolution.Unavailable -> return PageState.Unavailable to status(502, "Bad Gateway")
|
||||
}
|
||||
@@ -112,11 +117,23 @@ class KurdSiteServer(
|
||||
val open = PageState.Open(resolution, root, onChainVersion)
|
||||
return when (val result = fetcher.fetch(root, segments)) {
|
||||
is KurdContentFetcher.Result.File -> open to Response(200, "OK", mimeTypeOf(result.path.lastOrNull()), result.bytes)
|
||||
KurdContentFetcher.Result.NotFound -> open to status(404, "Not Found")
|
||||
KurdContentFetcher.Result.NotFound -> open to if (mainFrame) notFoundPage(root) else status(404, "Not Found")
|
||||
KurdContentFetcher.Result.Unavailable -> PageState.Unavailable to status(502, "Bad Gateway")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A page the site does not have: its own `/404.html` when it ships one, as a web server would
|
||||
* answer, and otherwise a line of text. Never an empty body, which WebView replaces with its
|
||||
* own error screen as if the site could not be reached.
|
||||
*/
|
||||
private suspend fun notFoundPage(root: Cid): Response {
|
||||
val page = fetcher.fetch(root, listOf(NOT_FOUND_PAGE)) as? KurdContentFetcher.Result.File
|
||||
?: return Response(404, "Not Found", "text/plain", "404 Not Found".toByteArray())
|
||||
|
||||
return Response(404, "Not Found", mimeTypeOf(NOT_FOUND_PAGE), page.bytes)
|
||||
}
|
||||
|
||||
private suspend fun resolve(name: KurdName): KurdResolution {
|
||||
val now = clock()
|
||||
resolutions[name]?.let { (at, resolution) -> if (now - at < resolutionTtlMillis) return resolution }
|
||||
@@ -127,6 +144,8 @@ class KurdSiteServer(
|
||||
|
||||
companion object {
|
||||
|
||||
private const val NOT_FOUND_PAGE = "404.html"
|
||||
|
||||
const val CONTENT_SECURITY_POLICY = "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; " +
|
||||
"img-src 'self' data: blob:; media-src 'self' blob:; font-src 'self' data:; connect-src 'self'; " +
|
||||
"worker-src 'none'; object-src 'none'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'"
|
||||
|
||||
@@ -32,6 +32,28 @@ class KurdNameTest {
|
||||
assertEquals("gov", KurdName.parse("serok.gov.kurd")!!.top)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a page address keeps its path, query and fragment`() {
|
||||
assertEquals("dks-news.kurd" to "/kategori/ekonomi", address("https://DKS-News.kurd/kategori/ekonomi"))
|
||||
assertEquals("dks-news.kurd" to "/a/x?lang=kmr#top", address("dks-news.kurd/a/x?lang=kmr#top"))
|
||||
assertEquals("dks-news.kurd" to "/?q=1", address("dks-news.kurd?q=1"))
|
||||
assertEquals("dks.kurd" to "/", address("dks.kurd"))
|
||||
assertEquals("dks.kurd" to "/", address("https://dks.kurd/"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a page address with an invalid name, port, user or unsafe path is refused`() {
|
||||
listOf(
|
||||
"dks_news.kurd/a", // the name itself
|
||||
"dks.kurd:8080/a",
|
||||
"user@dks.kurd/a",
|
||||
"http://dks.kurd/a", // only https, as for a bare name
|
||||
"dks.kurd/a b",
|
||||
"dks.kurd/\u00e7",
|
||||
"dks.kurd/a%zz",
|
||||
).forEach { assertNull(it, KurdName.parseAddress(it)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `names the pallet refuses are never parsed`() {
|
||||
listOf(
|
||||
@@ -84,4 +106,6 @@ class KurdNameTest {
|
||||
}
|
||||
|
||||
private fun node(name: String) = KurdName.parse(name)!!.node.toHexString()
|
||||
|
||||
private fun address(input: String) = KurdName.parseAddress(input)?.let { (name, path) -> name.name to path }
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package io.novafoundation.nova.runtime.names
|
||||
import io.novafoundation.nova.runtime.names.RealKurdNameResolver.Companion.judge
|
||||
import io.novafoundation.nova.runtime.names.RealKurdNameResolver.Companion.refuseOrGiveUp
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
@@ -35,6 +36,18 @@ class KurdResolutionJudgeTest {
|
||||
assertFalse(resolution.official)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a suspended name is suspended however it was read, even one that must be verified`() {
|
||||
val suspension = NameSuspension(until = 1, reg = 9, reason = "0x00", by = NameSuspension.By.COURT)
|
||||
val stopped = { raw: NameRecord -> NameLookup.Found(raw, NameStatus.ACTIVE, listOf("raw"), locked = false, suspension = suspension) }
|
||||
|
||||
val proven = judge(ahmet, stopped(leased()), verified = true) as KurdResolution.Suspended
|
||||
assertTrue(proven.verified)
|
||||
assertSame(suspension, proven.suspension)
|
||||
assertTrue(judge(ahmet, stopped(leased()), verified = false) is KurdResolution.Suspended)
|
||||
assertTrue(judge(dks, stopped(NameRecord.decode(NameFixtures.DKS)), verified = false) is KurdResolution.Suspended)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `with no answer a zone name is refused and any other is unavailable`() {
|
||||
assertTrue(refuseOrGiveUp(KurdName.parse("serok.gov.kurd")!!) is KurdResolution.Refused)
|
||||
|
||||
@@ -107,6 +107,76 @@ class NameLookupTest {
|
||||
assertFalse(first.agreesWith(NameLookup.NotFound))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a suspension of the name or of the name above it stops it`() = runBlocking {
|
||||
val govReg = NameRecord.decode(NameFixtures.GOV).reg
|
||||
val serokReg = NameRecord.decode(NameFixtures.SEROK_GOV).reg
|
||||
val live = { FakeReader().put(gov, NameFixtures.GOV).put(serok, NameFixtures.SEROK_GOV) }
|
||||
|
||||
assertEquals(null, (NameLookup.read(live(), serok) as NameLookup.Found).suspension)
|
||||
|
||||
val own = NameLookup.read(live().suspend(serok, serokReg, NameSuspension.By.EMERGENCY), serok) as NameLookup.Found
|
||||
assertEquals(NameSuspension.By.EMERGENCY, own.suspension?.by)
|
||||
|
||||
val above = NameLookup.read(live().suspend(gov, govReg, NameSuspension.By.COURT), serok) as NameLookup.Found
|
||||
assertEquals(NameSuspension.By.COURT, above.suspension?.by)
|
||||
assertEquals(NameFixtures.NOW + 1, above.suspension?.until)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a suspension that ran out or names another registration stops nothing`() = runBlocking {
|
||||
val serokReg = NameRecord.decode(NameFixtures.SEROK_GOV).reg
|
||||
val live = { FakeReader().put(gov, NameFixtures.GOV).put(serok, NameFixtures.SEROK_GOV) }
|
||||
|
||||
val ranOut = live().suspend(serok, serokReg, NameSuspension.By.COURT, until = NameFixtures.NOW)
|
||||
assertEquals(null, (NameLookup.read(ranOut, serok) as NameLookup.Found).suspension)
|
||||
|
||||
val earlier = live().suspend(serok, serokReg - 1, NameSuspension.By.COURT)
|
||||
assertEquals(null, (NameLookup.read(earlier, serok) as NameLookup.Found).suspension)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a suspension above a name that is not a subname does not reach it`() = runBlocking {
|
||||
// serok.gov.kurd as if Parliament had granted it outright rather than set it under gov.kurd
|
||||
val granted = NameFixtures.SEROK_GOV.copyOf().also { it[SEROK_KIND_OFFSET] = 1 }
|
||||
check(NameRecord.decode(granted).kind == NameRecord.Kind.GRANTED)
|
||||
val reader = FakeReader().put(gov, NameFixtures.GOV).put(serok, granted)
|
||||
.suspend(gov, NameRecord.decode(NameFixtures.GOV).reg, NameSuspension.By.COURT)
|
||||
|
||||
assertEquals(null, (NameLookup.read(reader, serok) as NameLookup.Found).suspension)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sources that disagree on a suspension do not agree`() = runBlocking {
|
||||
val serokReg = NameRecord.decode(NameFixtures.SEROK_GOV).reg
|
||||
val live = { FakeReader().put(gov, NameFixtures.GOV).put(serok, NameFixtures.SEROK_GOV) }
|
||||
|
||||
val plain = NameLookup.read(live(), serok)
|
||||
val stopped = NameLookup.read(live().suspend(serok, serokReg, NameSuspension.By.COURT), serok)
|
||||
assertFalse(plain.agreesWith(stopped))
|
||||
assertTrue(stopped.agreesWith(NameLookup.read(live().suspend(serok, serokReg, NameSuspension.By.COURT), serok)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `suspensions are read from the pallet's own storage item`() {
|
||||
// twox128("Navnisan") ++ twox128("Suspensions"), computed apart from this code
|
||||
val prefix = "8dada8db66ab8573e0db54b9f7d276265dd5f3679e83b14ce6d7b388fae08646"
|
||||
assertEquals(prefix + "00".repeat(32), NameLookup.suspensionsKey(ByteArray(32)).toHexString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a suspension decodes field by field and refuses trailing bytes`() {
|
||||
val raw = suspensionBytes(until = 0x0102, reg = 7, by = NameSuspension.By.EMERGENCY)
|
||||
val suspension = NameSuspension.decode(raw)
|
||||
|
||||
assertEquals(0x0102L, suspension.until)
|
||||
assertEquals(7L, suspension.reg)
|
||||
assertEquals("0x" + "ab".repeat(32), suspension.reason)
|
||||
assertEquals(NameSuspension.By.EMERGENCY, suspension.by)
|
||||
assertTrue(runCatching { NameSuspension.decode(raw + 0) }.isFailure)
|
||||
assertTrue(runCatching { NameSuspension.decode(raw.copyOf(raw.size - 1) + 2) }.isFailure)
|
||||
}
|
||||
|
||||
private fun record(kind: NameRecord.Kind, expiry: Long?, reg: Long = 1, parentReg: Long = 1) = NameRecord(
|
||||
label = "x", parent = ByteArray(32), parentReg = parentReg, reg = reg, owner = NameRecord.Owner.Governance, kind = kind,
|
||||
lockedTransfer = false, expiry = expiry, account = null, content = null,
|
||||
@@ -125,6 +195,10 @@ class NameLookupTest {
|
||||
|
||||
fun lock(name: KurdName) = apply { values[NameLookup.lockedKey(name.node).toHexString()] = byteArrayOf(0) }
|
||||
|
||||
fun suspend(name: KurdName, reg: Long, by: NameSuspension.By, until: Long = NameFixtures.NOW + 1) = apply {
|
||||
values[NameLookup.suspensionsKey(name.node).toHexString()] = suspensionBytes(until, reg, by)
|
||||
}
|
||||
|
||||
override suspend fun finalizedHead() = HEAD
|
||||
|
||||
override suspend fun blockNumber(at: String): Long = 1_284_551
|
||||
@@ -138,4 +212,16 @@ class NameLookupTest {
|
||||
const val HEAD = "0xfinalized"
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
/** Label (1 + 5), parent, parent_reg, reg, owner `Office(3)`: the kind byte follows. */
|
||||
private const val SEROK_KIND_OFFSET = 6 + 32 + 8 + 8 + 2
|
||||
|
||||
/** `Suspension { until, reg, reason, by }` as the pallet encodes it. */
|
||||
fun suspensionBytes(until: Long, reg: Long, by: NameSuspension.By): ByteArray =
|
||||
le64(until) + le64(reg) + ByteArray(32) { 0xab.toByte() } + byteArrayOf(by.ordinal.toByte())
|
||||
|
||||
private fun le64(value: Long) = ByteArray(8) { (value ushr (8 * it)).toByte() }
|
||||
}
|
||||
}
|
||||
+34
@@ -5,6 +5,7 @@ import io.novafoundation.nova.runtime.names.KurdNameResolver
|
||||
import io.novafoundation.nova.runtime.names.KurdResolution
|
||||
import io.novafoundation.nova.runtime.names.NameRecord
|
||||
import io.novafoundation.nova.runtime.names.NameStatus
|
||||
import io.novafoundation.nova.runtime.names.NameSuspension
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
@@ -37,6 +38,26 @@ class KurdSiteServerTest {
|
||||
assertEquals(404, server(resolved(content = null)).serve(name.name, "/").status)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a page the site lacks is its own 404 page, or a line of text, never an empty error`() = runBlocking {
|
||||
val withPage = KurdSiteServer(
|
||||
resolverOf(resolved(ipfs(cid("bafybeiezwrv6dr544fbj4xtthdg63jblfzqj5j6cqfkslbf7hkbevgpkui")))),
|
||||
fetcher(CarSource { _, _, _ -> resource("site-with-404.car") }),
|
||||
)
|
||||
val ownPage = withPage.serve("dks.kurd", "/missing", mainFrame = true)
|
||||
assertEquals(404, ownPage.status)
|
||||
assertEquals("text/html", ownPage.mimeType)
|
||||
assertTrue(String(ownPage.body).contains("<title>404 page</title>"))
|
||||
|
||||
val withoutPage = server(resolved(ipfs(siteRoot)))
|
||||
val text = withoutPage.serve("dks.kurd", "/missing", mainFrame = true)
|
||||
assertEquals(404, text.status)
|
||||
assertTrue(text.body.isNotEmpty())
|
||||
|
||||
// A missing image or script is answered as before: the page decides what to show
|
||||
assertEquals(0, withPage.serve("dks.kurd", "/missing.png").body.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `content the server cannot verify is not served`() = runBlocking {
|
||||
val ipns = NameRecord.Content.Ipfs(byteArrayOf(0xe5.toByte(), 0x01) + siteRoot.bytes)
|
||||
@@ -115,6 +136,19 @@ class KurdSiteServerTest {
|
||||
assertSame(KurdSiteServer.PageState.NotRegistered, stateFor { KurdResolution.NotFound(it, verified = true) })
|
||||
assertSame(KurdSiteServer.PageState.Unavailable, stateFor { KurdResolution.Unavailable(it) })
|
||||
assertSame(KurdSiteServer.PageState.NoSite, stateFor(resolved(content = null)))
|
||||
|
||||
val suspension = NameSuspension(until = 1, reg = 1, reason = "0x00", by = NameSuspension.By.EMERGENCY)
|
||||
val suspended = stateFor { KurdResolution.Suspended(it, suspension, verified = true) }
|
||||
assertSame(suspension, (suspended as KurdSiteServer.PageState.Suspended).suspension)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a suspended name serves nothing, not even its content when verified`() = runBlocking {
|
||||
val suspension = NameSuspension(until = 1, reg = 1, reason = "0x00", by = NameSuspension.By.COURT)
|
||||
val response = server { KurdResolution.Suspended(it, suspension, verified = true) }.serve("dks.kurd", "/")
|
||||
|
||||
assertEquals(451, response.status)
|
||||
assertTrue(response.body.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,3 +2,7 @@ CAR fixtures from [ipfs/gateway-conformance](https://github.com/ipfs/gateway-con
|
||||
at commit `eaca278518dc977db10bfec4acd79c92c4ee11ac` (`fixtures/trustless_gateway_car/` and
|
||||
`fixtures/path_gateway_unixfs/`), produced by Kubo. Dual licensed MIT / Apache-2.0 by their authors.
|
||||
Unmodified; used to check the wallet's CAR and UnixFS verifier against the reference implementation.
|
||||
|
||||
`site-with-404.car` is the wallet's own: a directory holding `index.html` and `404.html`, added with
|
||||
Kubo 0.43.1 (`ipfs add -r --cid-version 1 --raw-leaves`, root
|
||||
`bafybeiezwrv6dr544fbj4xtthdg63jblfzqj5j6cqfkslbf7hkbevgpkui`) and exported with `ipfs dag export`.
|
||||
Binary file not shown.
Reference in new issue
Block a user