~nskaggs/+junk/juju-packaging-test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
package httprequest_test

import (
	"net/http"
	"strings"

	gc "gopkg.in/check.v1"

	"github.com/juju/httprequest"
)

type checkIsJSONSuite struct{}

var _ = gc.Suite(&checkIsJSONSuite{})

var checkIsJSONTests = []struct {
	about       string
	contentType string
	body        string
	expectError string
}{{
	about:       "simple json",
	contentType: "application/json",
	body:        "not json but unread",
}, {
	about:       "simple json with charset",
	contentType: "application/json; charset=UTF-8",
	body:        "not json but unread",
}, {
	about:       "plain text",
	contentType: "text/plain; charset=UTF-8",
	body:        "   some\n   text\t\n",
	expectError: `unexpected content type text/plain; want application/json; content: some; text`,
}, {
	about:       "plain text with leading newline",
	contentType: "text/plain; charset=UTF-8",
	body:        "\nsome text",
	expectError: `unexpected content type text/plain; want application/json; content: some text`,
}, {
	about:       "unknown content type",
	contentType: "something",
	body:        "some  \nstuff",
	expectError: `unexpected content type something; want application/json; content: "some  \\nstuff"`,
}, {
	about:       "bad content type",
	contentType: "/; charset=foo",
	body:        `some stuff`,
	expectError: `unexpected content type "/; charset=foo"; want application/json; content: "some stuff"`,
}, {
	about:       "large text body",
	contentType: "text/plain",
	body:        strings.Repeat("x", 1024+300),
	expectError: `unexpected content type text/plain; want application/json; content: ` + strings.Repeat("x", 1024) + ` \.\.\. \[300 bytes omitted]`,
}, {
	about:       "html with no text",
	contentType: "text/html",
	body:        "<html><a href=\"foo\">\n</a></html>",
	expectError: `unexpected content type text/html; want application/json; content: "<html><a href=\\"foo\\">\\n</a></html>"`,
}, {
	about:       "non-utf8 text",
	contentType: "text/plain; charset=iso8859-1",
	body:        "Pepp\xe9\n",
	// It would be nice to make this better, but we don't
	// really want to drag in all the charsets for this.
	expectError: "unexpected content type text/plain; want application/json; content: Pepp\uFFFD",
}, {
	about:       "actual html error message from proxy",
	contentType: "text/html; charset=UTF-8",
	body: `<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Proxy Error</title>
</head><body>
<h1>Proxy Error</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
The proxy server could not handle the request <em><a href="/identity/v1/wait">GET&nbsp;/identity/v1/wait</a></em>.<p>
Reason: <strong>Error reading from remote server</strong></p></p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at api.jujucharms.com Port 443</address>
</body></html>`,
	expectError: `unexpected content type text/html; want application/json; content: 502 Proxy Error; Proxy Error; The proxy server received an invalid response from an upstream server; The proxy server could not handle the request; GET /identity/v1/wait; Reason:; Error reading from remote server; Apache/2\.4\.7 \(Ubuntu\) Server at api.jujucharms.com Port 443`,
}, {
	about:       "actual html error message web page",
	contentType: "text/html; charset=UTF-8",
	body: `<!doctype html>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en" dir="ltr"> <![endif]-->
<!--[if IE 7]>    <html class="lt-ie9 lt-ie8" lang="en" dir="ltr"> <![endif]-->
<!--[if IE 8]>    <html class="lt-ie9" lang="en" dir="ltr"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" dir="ltr" itemscope itemtype="http://schema.org/Product"> <!--<![endif]-->
<head>

<title>Page not found | Juju</title>

<meta charset="UTF-8" />
<meta name="description" content="Deploy, manage and scale your environments on any cloud." />
<meta name="keywords" content="juju, charms, services, service orchestration, cloud, deployment, puppet, chef, fuel, cloud tools, service management, cloud management, configuration management, linux tool, openstack tool, ubuntu, cloud design, cloud orchestration" />


<meta name="author" content="Canonical" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<![endif]-->

<link rel="shortcut icon" href="/static/img/favicon.ico" type="image/x-icon" />

<link rel="apple-touch-icon-precomposed" sizes="57x57" href="/static/img/icons/apple-touch-icon-57x57-precomposed.png"/>
<link rel="apple-touch-icon-precomposed" sizes="60x60" href="/static/img/icons/apple-touch-icon-60x60-precomposed.png"/>
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/icons/apple-touch-icon-72x72-precomposed.png"/>
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="/static/img/icons/apple-touch-icon-76x76-precomposed.png"/>
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/icons/apple-touch-icon-114x114-precomposed.png"/>
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="/static/img/icons/apple-touch-icon-120x120-precomposed.png"/>
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/icons/apple-touch-icon-144x144-precomposed.png"/>
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="/static/img/icons/apple-touch-icon-152x152-precomposed.png"/>
<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/static/img/icons/apple-touch-icon-180x180-precomposed.png"/>
<link rel="apple-touch-icon-precomposed" href="/static/img/icons/apple-touch-icon-precomposed.png"/>


<!-- google fonts -->
<link href='https://fonts.googleapis.com/css?family=Ubuntu:400,300,300italic,400italic,700,700italic%7CUbuntu+Mono' rel='stylesheet' type='text/css' />

<!-- stylesheets -->
<link rel="stylesheet" type="text/css" media="screen" href="//assets.ubuntu.com/sites/guidelines/css/responsive/latest/ubuntu-styles.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/static/css/build.css" />

<!-- load basic yui, our modules file, the loader and sub to set up modules with
combo load -->
<script type="text/javascript"
    
    src="/prod/combo?yui/yui/yui-min.js&amp;app/modules-min.js&amp;yui/loader/loader-min.js&amp;yui/substitute/substitute-min.js&amp;plugins/respond.min.js&amp;plugins/modernizr.2.7.1.js&amp;plugins/handlebars.runtime-v2.0.0.js&amp;plugins/highlight.pack.js&amp;templates/templates.js">
    
</script>

<script type="text/javascript">
      YUI.GlobalConfig = {
          combine: true,
          base: '/prod/combo?yui/',
          comboBase: '/prod/combo?',
          maxURLLength: 1300,
          root: 'yui/',
            groups: {
              app: {
                  combine: true,
                  base: '/prod/combo?app',
                  comboBase: '/prod/combo?',
                  root: 'app/',
                  
                  filter: 'min',
                  
                  // From modules.js
                  modules: YUI_MODULES,
              }
          },
          static_root:'/static/'
    };
 </script>

<!-- provide charmstore url -->
<script type="text/javascript">
    window.csUrl = "https://api.jujucharms.com/charmstore/v4";
</script>


<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@ubuntucloud">
<meta name="twitter:creator" content="@ubuntucloud">
<meta name="twitter:domain" content="jujucharms.com">
<meta name="twitter:title" content="Search results for foo in Juju">
<meta name="twitter:description" content="Deploy, manage, and scale your environments on any cloud.">
<meta name="twitter:image" content="https://jujucharms.com/static/img/juju-twitter.png">


</head>

<body class="
no-results no-match">

<header class="banner global" role="banner">

    <nav role="navigation" class="nav-primary nav-right">
    

    <span class="accessibility-aid">
        <a accesskey="s" href="#main-content">Jump to content</a>
    </span>
    <ul>
        <li>
    <a
        class=""
        href="/store"
    >
       Store
    </a>
    </li>
        <li><a href="https://demo.jujucharms.com" target="_blank" >Demo</a></li>
        <li>
    <a
        class=""
        href="/about"
    >
       About
    </a>
    </li>
        <li>
    <a
        class=""
        href="/about/features"
    >
       Features
    </a>
    </li>
        <li>
    <a
        class=""
        href="/community"
    >
       Community
    </a>
    </li>
        <li>
    <a
        class=""
        href="/docs/"
    >
       Docs
    </a>
    </li>
        <li>
    <a
        class=""
        href="/get-started"
    >
       Get started
    </a>
    </li>
    </ul>
    <ul class="user-nav">
        <li class="user-dropdown"><span id="user-dropdown"></span></li>
    </ul>
    <a href="#canonlist" class="nav-toggle no-script">☰</a>
</nav>

</header>



<div class="contextual-bar">
    
    <div class="logo">
        <a class="logo-ubuntu" href="/">
            <img width="73" height="30" src="/static/img/logos/logo.png" alt="" />
        </a>
    </div>
    <ul class="directory-path">
        <li><a href="https://demo.jujucharms.com" class="btn__see--more">Create <span>+</span></a></li>
    </ul>

    <form class="search-form" action="/q" method="GET">
    <input
        type="search" name="text"
        class="form-text" placeholder="Search the store"
        value="foo"
    />
    <button type="submit">
        <img
            src="/static/img/icons/search_16_active.svg"
            alt="Search" height="28"
        />
    </button>
    <a href="" class="search-close"><img src="/static/img/icons/close_16.svg" alt="" /></a>
</form>


</div>

<div class="wrapper">
<div id="main-content">





    
    <div class="row">
        <div class="inner-wrapper">
            <h2 class="error-title">404: Sorry, we couldn&rsquo;t find the page.</h2>
            
            <p class="cta">Try a different URL, try searching for solutions or learn how to <a href="/docs/authors-charm-writing">create your own solution</a>.</p>
            <nav class="error-nav">
                <ul>
                    <li><a href="/store" class="link-cta-positive">Browse the store</a></li>
                    <li><a href="/q/?type=bundle" class="link-cta-negative">All bundles</a></li>
                    <li><a href="/q/?type=charm" class="link-cta-negative">All charms</a></li>
                    <li><a href="https://github.com/CanonicalLtd/jujucharms.com/issues">Submit a bug</a></li>
                </ul>
            </nav>
            
        </div>
    </div>



</div><!-- /.inner-wrapper -->

</div><!-- /.wrapper -->


<div class="footer-wrapper strip-light">
<div class="store-cta">
    <a href="/store">Browse the store&nbsp;&rsaquo;</a>
</div>
<footer class="global clearfix">
    <p class="top-link">
        <a href="#">Back to the top</a>
    </p>
    <nav role="navigation" class="inner-wrapper">
        <div class="row">
            <div class="seven-col">
                <ul class="no-bullets">
                    <li><a class="external" href="https://demo.jujucharms.com">Demo</a></li>
                    <li><a href="/about">About</a></li>
                    <li><a href="/about/features">Features</a></li>
                    <li><a href="/docs">Docs</a></li>
                    <li><a href="/get-started">Get Started</a></li>
                </ul>
            </div>
            <div class="five-col last-col">
                <ul class="social--right">
                    <li class="social__item">
                        <a href="https://plus.google.com/106305712267007929608/posts" class="social__google"><span class="accessibility-aid">Juju on Google+</span></a>
                    </li>
                    <li class="social__item">
                        <a href="http://www.twitter.com/ubuntucloud" class="social__twitter"><span class="accessibility-aid">Ubuntu Cloud on Twitter</span></a>
                    </li>
                    <li class="social__item">
                        <a href="http://www.facebook.com/ubuntucloud" class="social__facebook"><span class="accessibility-aid">Ubuntu Cloud on Facebook</span></a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="legal clearfix">
        <div class="legal-inner">
            <p class="twelve-col">
                &copy; 2015 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.
            </p>
            <ul class="inline bullets clear">
                <li><a href="http://www.ubuntu.com/legal">Legal information</a></li>
                <li><a href="https://github.com/CanonicalLtd/jujucharms.com/issues">Report a bug on this site</a></li>
            </ul>
            <span class="accessibility-aid">
                <a href="#">Got to the top of the page</a>
            </span>
        </div>
    </div>
</footer>
</div>

<script>
    var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);
    if(isOperaMini) {
        var root = document.documentElement;
        root.className += " opera-mini";
    }
</script>

<script>
YUI().use('storefront-cookie', 'storefront-utils', 'user-dropdown',
          function (Y) {
    Y.on('domready', function() {
        var inSession = false;
        var cookie = new Y.storefront.CookiePolicy();
        var utils = Y.storefront.utils;

        cookie.render();
        utils.mobileNav(Y.one('header.banner'));
        utils.setupSearch();
        var userDropdown = new Y.storefront.UserDropdownView({
            container: Y.one('#user-dropdown')
        });
        userDropdown.set('authenticated', inSession);
        
        if (inSession) {
            userDropdown.set('username', '');
        }
        userDropdown.render();
    });
});
</script>


<script type="text/template" id="cookie-warning-template">
    <div class="cookie-policy">
        <div class="inner-wrapper">
            <a href="?cp=close" class="link-cta">Close</a>
            <p>We use cookies to improve your experience. By your continued use of this site you accept such use. To change your settings please <a href="http://www.ubuntu.com/legal/terms-and-policies/privacy-policy#cookies">see our policy</a>.</p>
        </div>
    </div>
</script>


<script>
    YUI().use('node', 'search-view', function (Y) {
        Y.on('domready', function() {
            var view = new Y.storefront.SearchView({
                container: Y.one('#main-content')
            });
            view.render();
        });
    });
</script>


<!-- google analytics -->
<script>
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-1018242-44']);
  _gaq.push(['_trackPageview']);

  (function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>


<!-- {version: ['0.1.29', '']} -->

</body>
</html>
`,
	expectError: `unexpected content type text/html; want application/json; content: Page not found | Juju; Jump to content; Store; Demo; About; Features; Community; Docs; Get started; ☰; Create; \+; 404: Sorry, we couldn’t find the page; Try a different URL, try searching for solutions or learn how to; create your own solution; Browse the store; All bundles; All charms; Submit a bug; Browse the store ›; Back to the top; Demo; About; Features; Docs; Get Started; Juju on Google+; Ubuntu Cloud on Twitter; Ubuntu Cloud on Facebook; © 2015 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd; Legal information; Report a bug on this site; Got to the top of the page`,
}}

func (checkIsJSONSuite) TestCheckIsJSON(c *gc.C) {
	*httprequest.MaxErrorBodySize = 16 * 1024
	for i, test := range checkIsJSONTests {
		c.Logf("test %d: %s", i, test.about)
		r := strings.NewReader(test.body)
		err := httprequest.CheckIsJSON(http.Header{
			"Content-Type": {test.contentType},
		}, r)
		if test.expectError == "" {
			c.Assert(err, gc.IsNil)
			c.Assert(r.Len(), gc.Equals, len(test.body))
			continue
		}
		c.Assert(err, gc.ErrorMatches, test.expectError)
		if len(test.body) > *httprequest.MaxErrorBodySize {
			c.Assert(r.Len(), gc.Equals, *httprequest.MaxErrorBodySize-len(test.body))
		}
	}
}