@@ -577,6 +577,92 @@ func TestRedirects(t *testing.T) {
577577 do (http .MethodGet )
578578 do (http .MethodHead )
579579 })
580+
581+ t .Run ("Superfluous namespace" , func (t * testing.T ) {
582+ t .Parallel ()
583+
584+ backend , root := newMockBackend (t , "fixtures.car" )
585+ backend .namesys ["/ipns/dnslink-gateway.com" ] = newMockNamesysItem (path .FromCid (root ), 0 )
586+ backend .namesys ["/ipns/dnslink-website.com" ] = newMockNamesysItem (path .FromCid (root ), 0 )
587+
588+ ts := newTestServerWithConfig (t , backend , Config {
589+ NoDNSLink : false ,
590+ PublicGateways : map [string ]* PublicGateway {
591+ "dnslink-gateway.com" : {
592+ Paths : []string {"/ipfs" , "/ipns" },
593+ NoDNSLink : false ,
594+ DeserializedResponses : true ,
595+ },
596+ "dnslink-website.com" : {
597+ Paths : []string {},
598+ NoDNSLink : false ,
599+ DeserializedResponses : true ,
600+ },
601+ "gateway.com" : {
602+ Paths : []string {"/ipfs" },
603+ UseSubdomains : false ,
604+ NoDNSLink : true ,
605+ DeserializedResponses : true ,
606+ },
607+ "subdomain-gateway.com" : {
608+ Paths : []string {"/ipfs" , "/ipns" },
609+ UseSubdomains : true ,
610+ NoDNSLink : true ,
611+ DeserializedResponses : true ,
612+ },
613+ },
614+ DeserializedResponses : true ,
615+ })
616+
617+ for _ , test := range []struct {
618+ host string
619+ path string
620+ status int
621+ location string
622+ }{
623+ // Barebones gateway
624+ {"" , "/ipfs/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" , http .StatusMovedPermanently , "/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" },
625+ {"" , "/ipfs/ipns/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" , http .StatusMovedPermanently , "/ipns/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" },
626+ {"" , "/ipfs/ipns/dnslink.com" , http .StatusMovedPermanently , "/ipns/dnslink.com" },
627+
628+ // DNSLink Gateway with /ipfs and /ipns enabled
629+ {"dnslink-gateway.com" , "/ipfs/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" , http .StatusMovedPermanently , "/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" },
630+ {"dnslink-gateway.com" , "/ipfs/ipns/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" , http .StatusMovedPermanently , "/ipns/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" },
631+ {"dnslink-gateway.com" , "/ipfs/ipns/dnslink.com" , http .StatusMovedPermanently , "/ipns/dnslink.com" },
632+
633+ // DNSLink Gateway without /ipfs and /ipns
634+ {"dnslink-website.com" , "/ipfs/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" , http .StatusNotFound , "" },
635+ {"dnslink-website.com" , "/ipfs/ipns/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" , http .StatusNotFound , "" },
636+ {"dnslink-website.com" , "/ipfs/ipns/dnslink.com" , http .StatusNotFound , "" },
637+
638+ // Public gateway
639+ {"gateway.com" , "/ipfs/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" , http .StatusMovedPermanently , "/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" },
640+ {"gateway.com" , "/ipfs/ipns/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" , http .StatusMovedPermanently , "/ipns/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" },
641+ {"gateway.com" , "/ipfs/ipns/dnslink.com" , http .StatusMovedPermanently , "/ipns/dnslink.com" },
642+
643+ // Subdomain gateway
644+ {"subdomain-gateway.com" , "/ipfs/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" , http .StatusMovedPermanently , "/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" },
645+ {"subdomain-gateway.com" , "/ipfs/ipns/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" , http .StatusMovedPermanently , "/ipns/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" },
646+ {"subdomain-gateway.com" , "/ipfs/ipns/dnslink.com" , http .StatusMovedPermanently , "/ipns/dnslink.com" },
647+ } {
648+ testName := ts .URL + test .path
649+ if test .host != "" {
650+ testName += " " + test .host
651+ }
652+
653+ t .Run (testName , func (t * testing.T ) {
654+ req := mustNewRequest (t , http .MethodGet , ts .URL + test .path , nil )
655+ req .Header .Set ("Accept" , "text/html" )
656+ if test .host != "" {
657+ req .Host = test .host
658+ }
659+ resp := mustDoWithoutRedirect (t , req )
660+ defer resp .Body .Close ()
661+ require .Equal (t , test .status , resp .StatusCode )
662+ require .Equal (t , test .location , resp .Header .Get ("Location" ))
663+ })
664+ }
665+ })
580666}
581667
582668func TestDeserializedResponses (t * testing.T ) {
0 commit comments