1
package httprequest_test
9
"github.com/juju/httprequest"
12
type checkIsJSONSuite struct{}
14
var _ = gc.Suite(&checkIsJSONSuite{})
16
var checkIsJSONTests = []struct {
23
contentType: "application/json",
24
body: "not json but unread",
26
about: "simple json with charset",
27
contentType: "application/json; charset=UTF-8",
28
body: "not json but unread",
31
contentType: "text/plain; charset=UTF-8",
32
body: " some\n text\t\n",
33
expectError: `unexpected content type text/plain; want application/json; content: some; text`,
35
about: "plain text with leading newline",
36
contentType: "text/plain; charset=UTF-8",
38
expectError: `unexpected content type text/plain; want application/json; content: some text`,
40
about: "unknown content type",
41
contentType: "something",
43
expectError: `unexpected content type something; want application/json; content: "some \\nstuff"`,
45
about: "bad content type",
46
contentType: "/; charset=foo",
48
expectError: `unexpected content type "/; charset=foo"; want application/json; content: "some stuff"`,
50
about: "large text body",
51
contentType: "text/plain",
52
body: strings.Repeat("x", 1024+300),
53
expectError: `unexpected content type text/plain; want application/json; content: ` + strings.Repeat("x", 1024) + ` \.\.\. \[300 bytes omitted]`,
55
about: "html with no text",
56
contentType: "text/html",
57
body: "<html><a href=\"foo\">\n</a></html>",
58
expectError: `unexpected content type text/html; want application/json; content: "<html><a href=\\"foo\\">\\n</a></html>"`,
60
about: "non-utf8 text",
61
contentType: "text/plain; charset=iso8859-1",
63
// It would be nice to make this better, but we don't
64
// really want to drag in all the charsets for this.
65
expectError: "unexpected content type text/plain; want application/json; content: Pepp\uFFFD",
67
about: "actual html error message from proxy",
68
contentType: "text/html; charset=UTF-8",
69
body: `<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
71
<title>502 Proxy Error</title>
74
<p>The proxy server received an invalid
75
response from an upstream server.<br />
76
The proxy server could not handle the request <em><a href="/identity/v1/wait">GET /identity/v1/wait</a></em>.<p>
77
Reason: <strong>Error reading from remote server</strong></p></p>
79
<address>Apache/2.4.7 (Ubuntu) Server at api.jujucharms.com Port 443</address>
81
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`,
83
about: "actual html error message web page",
84
contentType: "text/html; charset=UTF-8",
85
body: `<!doctype html>
86
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en" dir="ltr"> <![endif]-->
87
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en" dir="ltr"> <![endif]-->
88
<!--[if IE 8]> <html class="lt-ie9" lang="en" dir="ltr"> <![endif]-->
89
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" dir="ltr" itemscope itemtype="http://schema.org/Product"> <!--<![endif]-->
92
<title>Page not found | Juju</title>
94
<meta charset="UTF-8" />
95
<meta name="description" content="Deploy, manage and scale your environments on any cloud." />
96
<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" />
99
<meta name="author" content="Canonical" />
100
<meta name="viewport" content="width=device-width, initial-scale=1" />
103
<meta http-equiv="X-UA-Compatible" content="IE=8">
106
<link rel="shortcut icon" href="/static/img/favicon.ico" type="image/x-icon" />
108
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="/static/img/icons/apple-touch-icon-57x57-precomposed.png"/>
109
<link rel="apple-touch-icon-precomposed" sizes="60x60" href="/static/img/icons/apple-touch-icon-60x60-precomposed.png"/>
110
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/icons/apple-touch-icon-72x72-precomposed.png"/>
111
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="/static/img/icons/apple-touch-icon-76x76-precomposed.png"/>
112
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/icons/apple-touch-icon-114x114-precomposed.png"/>
113
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="/static/img/icons/apple-touch-icon-120x120-precomposed.png"/>
114
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/icons/apple-touch-icon-144x144-precomposed.png"/>
115
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="/static/img/icons/apple-touch-icon-152x152-precomposed.png"/>
116
<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/static/img/icons/apple-touch-icon-180x180-precomposed.png"/>
117
<link rel="apple-touch-icon-precomposed" href="/static/img/icons/apple-touch-icon-precomposed.png"/>
120
<!-- google fonts -->
121
<link href='https://fonts.googleapis.com/css?family=Ubuntu:400,300,300italic,400italic,700,700italic%7CUbuntu+Mono' rel='stylesheet' type='text/css' />
124
<link rel="stylesheet" type="text/css" media="screen" href="//assets.ubuntu.com/sites/guidelines/css/responsive/latest/ubuntu-styles.css" />
125
<link rel="stylesheet" type="text/css" media="screen" href="/static/css/build.css" />
127
<!-- load basic yui, our modules file, the loader and sub to set up modules with
129
<script type="text/javascript"
131
src="/prod/combo?yui/yui/yui-min.js&app/modules-min.js&yui/loader/loader-min.js&yui/substitute/substitute-min.js&plugins/respond.min.js&plugins/modernizr.2.7.1.js&plugins/handlebars.runtime-v2.0.0.js&plugins/highlight.pack.js&templates/templates.js">
135
<script type="text/javascript">
138
base: '/prod/combo?yui/',
139
comboBase: '/prod/combo?',
145
base: '/prod/combo?app',
146
comboBase: '/prod/combo?',
152
modules: YUI_MODULES,
155
static_root:'/static/'
159
<!-- provide charmstore url -->
160
<script type="text/javascript">
161
window.csUrl = "https://api.jujucharms.com/charmstore/v4";
165
<meta name="twitter:card" content="summary">
166
<meta name="twitter:site" content="@ubuntucloud">
167
<meta name="twitter:creator" content="@ubuntucloud">
168
<meta name="twitter:domain" content="jujucharms.com">
169
<meta name="twitter:title" content="Search results for foo in Juju">
170
<meta name="twitter:description" content="Deploy, manage, and scale your environments on any cloud.">
171
<meta name="twitter:image" content="https://jujucharms.com/static/img/juju-twitter.png">
177
no-results no-match">
179
<header class="banner global" role="banner">
181
<nav role="navigation" class="nav-primary nav-right">
184
<span class="accessibility-aid">
185
<a accesskey="s" href="#main-content">Jump to content</a>
196
<li><a href="https://demo.jujucharms.com" target="_blank" >Demo</a></li>
208
href="/about/features"
238
<ul class="user-nav">
239
<li class="user-dropdown"><span id="user-dropdown"></span></li>
241
<a href="#canonlist" class="nav-toggle no-script">☰</a>
248
<div class="contextual-bar">
251
<a class="logo-ubuntu" href="/">
252
<img width="73" height="30" src="/static/img/logos/logo.png" alt="" />
255
<ul class="directory-path">
256
<li><a href="https://demo.jujucharms.com" class="btn__see--more">Create <span>+</span></a></li>
259
<form class="search-form" action="/q" method="GET">
261
type="search" name="text"
262
class="form-text" placeholder="Search the store"
265
<button type="submit">
267
src="/static/img/icons/search_16_active.svg"
268
alt="Search" height="28"
271
<a href="" class="search-close"><img src="/static/img/icons/close_16.svg" alt="" /></a>
277
<div class="wrapper">
278
<div id="main-content">
286
<div class="inner-wrapper">
287
<h2 class="error-title">404: Sorry, we couldn’t find the page.</h2>
289
<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>
290
<nav class="error-nav">
292
<li><a href="/store" class="link-cta-positive">Browse the store</a></li>
293
<li><a href="/q/?type=bundle" class="link-cta-negative">All bundles</a></li>
294
<li><a href="/q/?type=charm" class="link-cta-negative">All charms</a></li>
295
<li><a href="https://github.com/CanonicalLtd/jujucharms.com/issues">Submit a bug</a></li>
304
</div><!-- /.inner-wrapper -->
306
</div><!-- /.wrapper -->
309
<div class="footer-wrapper strip-light">
310
<div class="store-cta">
311
<a href="/store">Browse the store ›</a>
313
<footer class="global clearfix">
315
<a href="#">Back to the top</a>
317
<nav role="navigation" class="inner-wrapper">
319
<div class="seven-col">
320
<ul class="no-bullets">
321
<li><a class="external" href="https://demo.jujucharms.com">Demo</a></li>
322
<li><a href="/about">About</a></li>
323
<li><a href="/about/features">Features</a></li>
324
<li><a href="/docs">Docs</a></li>
325
<li><a href="/get-started">Get Started</a></li>
328
<div class="five-col last-col">
329
<ul class="social--right">
330
<li class="social__item">
331
<a href="https://plus.google.com/106305712267007929608/posts" class="social__google"><span class="accessibility-aid">Juju on Google+</span></a>
333
<li class="social__item">
334
<a href="http://www.twitter.com/ubuntucloud" class="social__twitter"><span class="accessibility-aid">Ubuntu Cloud on Twitter</span></a>
336
<li class="social__item">
337
<a href="http://www.facebook.com/ubuntucloud" class="social__facebook"><span class="accessibility-aid">Ubuntu Cloud on Facebook</span></a>
343
<div class="legal clearfix">
344
<div class="legal-inner">
345
<p class="twelve-col">
346
© 2015 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.
348
<ul class="inline bullets clear">
349
<li><a href="http://www.ubuntu.com/legal">Legal information</a></li>
350
<li><a href="https://github.com/CanonicalLtd/jujucharms.com/issues">Report a bug on this site</a></li>
352
<span class="accessibility-aid">
353
<a href="#">Got to the top of the page</a>
361
var isOperaMini = (navigator.userAgent.indexOf('Opera Mini') > -1);
363
var root = document.documentElement;
364
root.className += " opera-mini";
369
YUI().use('storefront-cookie', 'storefront-utils', 'user-dropdown',
371
Y.on('domready', function() {
372
var inSession = false;
373
var cookie = new Y.storefront.CookiePolicy();
374
var utils = Y.storefront.utils;
377
utils.mobileNav(Y.one('header.banner'));
379
var userDropdown = new Y.storefront.UserDropdownView({
380
container: Y.one('#user-dropdown')
382
userDropdown.set('authenticated', inSession);
385
userDropdown.set('username', '');
387
userDropdown.render();
393
<script type="text/template" id="cookie-warning-template">
394
<div class="cookie-policy">
395
<div class="inner-wrapper">
396
<a href="?cp=close" class="link-cta">Close</a>
397
<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>
404
YUI().use('node', 'search-view', function (Y) {
405
Y.on('domready', function() {
406
var view = new Y.storefront.SearchView({
407
container: Y.one('#main-content')
415
<!-- google analytics -->
417
var _gaq = _gaq || [];
418
_gaq.push(['_setAccount', 'UA-1018242-44']);
419
_gaq.push(['_trackPageview']);
422
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
423
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
424
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
429
<!-- {version: ['0.1.29', '']} -->
434
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`,
437
func (checkIsJSONSuite) TestCheckIsJSON(c *gc.C) {
438
*httprequest.MaxErrorBodySize = 16 * 1024
439
for i, test := range checkIsJSONTests {
440
c.Logf("test %d: %s", i, test.about)
441
r := strings.NewReader(test.body)
442
err := httprequest.CheckIsJSON(http.Header{
443
"Content-Type": {test.contentType},
445
if test.expectError == "" {
446
c.Assert(err, gc.IsNil)
447
c.Assert(r.Len(), gc.Equals, len(test.body))
450
c.Assert(err, gc.ErrorMatches, test.expectError)
451
if len(test.body) > *httprequest.MaxErrorBodySize {
452
c.Assert(r.Len(), gc.Equals, *httprequest.MaxErrorBodySize-len(test.body))