|
1 | 1 | package stack |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "net/http" |
4 | 5 | "slices" |
5 | 6 | "strings" |
6 | 7 | "testing" |
@@ -99,6 +100,60 @@ func TestDetectWPPlugins(t *testing.T) { |
99 | 100 | } |
100 | 101 | } |
101 | 102 |
|
| 103 | +func TestDetectCMS(t *testing.T) { |
| 104 | + tests := []struct { |
| 105 | + name string |
| 106 | + html string |
| 107 | + want string |
| 108 | + }{ |
| 109 | + { |
| 110 | + name: "Magento from data-mage-init", |
| 111 | + html: `<div data-mage-init='{"someWidget":{}}'></div>`, |
| 112 | + want: "Magento", |
| 113 | + }, |
| 114 | + { |
| 115 | + name: "Magento from static path", |
| 116 | + html: `<link href="/static/frontend/magento/luma/en_US/css/styles.css">`, |
| 117 | + want: "Magento", |
| 118 | + }, |
| 119 | + { |
| 120 | + name: "Magento not detected from image MIME types", |
| 121 | + html: `<link rel="icon" type="image/png" href="/fav.png"><img src="data:image/svg+xml;base64,abc">`, |
| 122 | + want: "", |
| 123 | + }, |
| 124 | + { |
| 125 | + name: "PrestaShop from module path", |
| 126 | + html: `<link href="/modules/ps_shoppingcart/css/cart.css">`, |
| 127 | + want: "PrestaShop", |
| 128 | + }, |
| 129 | + { |
| 130 | + name: "PrestaShop not detected from prose mention", |
| 131 | + html: `<p>We migrated from prestashop last year.</p>`, |
| 132 | + want: "", |
| 133 | + }, |
| 134 | + { |
| 135 | + name: "Webflow from data-wf-page", |
| 136 | + html: `<html data-wf-page="abc123" data-wf-site="def456">`, |
| 137 | + want: "Webflow", |
| 138 | + }, |
| 139 | + { |
| 140 | + name: "Webflow not detected from a link to webflow.com", |
| 141 | + html: `<a href="https://webflow.com">Built with Webflow</a>`, |
| 142 | + want: "", |
| 143 | + }, |
| 144 | + } |
| 145 | + |
| 146 | + for _, tt := range tests { |
| 147 | + t.Run(tt.name, func(t *testing.T) { |
| 148 | + r := &Result{} |
| 149 | + detectCMS(r, http.Header{}, strings.ToLower(tt.html)) |
| 150 | + if r.CMS != tt.want { |
| 151 | + t.Errorf("expected CMS %q, got %q", tt.want, r.CMS) |
| 152 | + } |
| 153 | + }) |
| 154 | + } |
| 155 | +} |
| 156 | + |
102 | 157 | func TestDetectJSLibs(t *testing.T) { |
103 | 158 | tests := []struct { |
104 | 159 | name string |
|
0 commit comments