<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Mocha on ZeroSharp</title><link>https://www.zerosharp.com/blog/categories/mocha/</link><description>Recent content in Mocha on ZeroSharp</description><generator>Hugo</generator><language>en-gb</language><copyright>Copyright © 2012–{year} Robert Anderson</copyright><lastBuildDate>Tue, 09 Feb 2016 11:31:00 +0100</lastBuildDate><atom:link href="https://www.zerosharp.com/blog/categories/mocha/index.xml" rel="self" type="application/rss+xml"/><item><title>Serverless Framework Part 5: Pulling in a node package</title><link>https://www.zerosharp.com/serverless-framework-part-5-pulling-in-a-node-package/</link><pubDate>Tue, 09 Feb 2016 11:31:00 +0100</pubDate><guid>https://www.zerosharp.com/serverless-framework-part-5-pulling-in-a-node-package/</guid><description>&lt;p&gt;This is the final part of an ongoing series about the &lt;a href="https://github.com/serverless/serverless"&gt;Serverless framework&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the previous posts, the &lt;code&gt;PasswordGenerator&lt;/code&gt; always returned &amp;lsquo;Password&amp;rsquo;. Instead each date should corresponds to a new unique password. We&amp;rsquo;ll make use of the &lt;a href="https://www.npmjs.com/package/crypto-js"&gt;Crypto-js&lt;/a&gt; node package and we&amp;rsquo;ll see that the AWS lambda copes just fine.&lt;/p&gt;
&lt;h3 id="installing-a-node-package"&gt;Installing a node package&lt;/h3&gt;
&lt;p&gt;Pull in the crypto-js package into the serverless component.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ cd nodejscomponent/
$ npm install crypto-js --save
crypto-js@3.1.6 node_modules/crypto-js
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we need the typescript definitions. Watch out there are two different TypeScript typings called &lt;em&gt;cryptojs&lt;/em&gt; and &lt;em&gt;crypto-js&lt;/em&gt;. The first one is more complete.&lt;/p&gt;</description></item><item><title>Serverless Framework - Part 4: Connecting the parts</title><link>https://www.zerosharp.com/serverless-framework-part-4-connecting-the-parts/</link><pubDate>Mon, 01 Feb 2016 09:44:00 +0100</pubDate><guid>https://www.zerosharp.com/serverless-framework-part-4-connecting-the-parts/</guid><description>&lt;p&gt;This is part of an ongoing series about the &lt;a href="https://github.com/serverless/serverless"&gt;Serverless framework&lt;/a&gt;: &lt;a href="https://www.zerosharp.com/serverless-framework-part-1-up-and-running/"&gt;Part 1&lt;/a&gt;, &lt;a href="https://www.zerosharp.com/serverless-framework-part-2-typescript-and-mocha/"&gt;part 2&lt;/a&gt;, &lt;a href="https://www.zerosharp.com/serverless-framework-part-3-the-guts/"&gt;part 3&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="new-version-031"&gt;New version 0.3.1&lt;/h2&gt;
&lt;p&gt;
&lt;span class="fluo"&gt;Edit: since the original version of this post, a new version 0.3.1 of Serverless was released. I have updated the tutorial below to reflect the newer version. Also, &lt;a href="https://github.com/DefinitelyTyped/tsd/issues/269"&gt;TSD has been deprecated&lt;/a&gt; in favour of &lt;a href="https://www.npmjs.com/package/typings"&gt;Typings&lt;/a&gt; so I&amp;rsquo;ve updated to use Typings instead.&lt;/span&gt;

All parts have been updated for the latest version of the framework 0.3.1.&lt;/p&gt;
&lt;h2 id="the-password-of-the-day-generator-class"&gt;The Password of the Day Generator class&lt;/h2&gt;
&lt;p&gt;First up we need a class to generate and check the password of the day. For the moment, let&amp;rsquo;s pretend the password of the day is always the string &lt;em&gt;&amp;ldquo;Password&amp;rdquo;&lt;/em&gt;. Put the following typescript class in &lt;em&gt;nodejscomponent/src&lt;/em&gt;.&lt;/p&gt;</description></item><item><title>Serverless Framework - Part 3: The guts of a serverless service</title><link>https://www.zerosharp.com/serverless-framework-part-3-the-guts/</link><pubDate>Fri, 29 Jan 2016 17:44:00 +0100</pubDate><guid>https://www.zerosharp.com/serverless-framework-part-3-the-guts/</guid><description>&lt;p&gt;This is part of an ongoing series about the &lt;a href="https://github.com/serverless/serverless"&gt;Serverless framework&lt;/a&gt;. For those following along, &lt;a href="https://www.zerosharp.com/serverless-framework-part-1-up-and-running/"&gt;part 1&lt;/a&gt; and &lt;a href="https://www.zerosharp.com/serverless-framework-part-2-typescript-and-mocha/"&gt;part 2&lt;/a&gt; have been updated for the current latest version of Serverless 0.3.1.&lt;/p&gt;
&lt;p&gt;In this post, we&amp;rsquo;ll discuss how a Serverless function actually works.&lt;/p&gt;
&lt;h2 id="the-guts-of-a-serverless-function"&gt;The guts of a serverless function&lt;/h2&gt;
&lt;p&gt;When we visited the deployed endpoint at the end of &lt;a href="https://www.zerosharp.com/serverless-framework-part-1-up-and-running/"&gt;part 1&lt;/a&gt;, it correctly returned some JSON content.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="err"&gt;message:&lt;/span&gt; &lt;span class="nt"&gt;&amp;#34;Your Serverless function ran successfully!&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Where does this message come from? Look at &lt;em&gt;index.js&lt;/em&gt; in the component&amp;rsquo;s &lt;em&gt;lib&lt;/em&gt; folder.&lt;/p&gt;</description></item><item><title>Serverless Framework - Part 2: TypeScript and Mocha</title><link>https://www.zerosharp.com/serverless-framework-part-2-typescript-and-mocha/</link><pubDate>Tue, 12 Jan 2016 08:08:00 +0100</pubDate><guid>https://www.zerosharp.com/serverless-framework-part-2-typescript-and-mocha/</guid><description>&lt;p&gt;Happy New Year everyone!&lt;/p&gt;
&lt;p&gt;This is the second part of a series about the &lt;a href="https://github.com/serverless/serverless"&gt;Serverless&lt;/a&gt; framework. Read &lt;a href="https://www.zerosharp.com/serverless-framework-part-1-up-and-running/"&gt;the first part&lt;/a&gt; to get up and running.&lt;/p&gt;
&lt;p&gt;First I&amp;rsquo;ll describe the webservice I&amp;rsquo;m building. Then we&amp;rsquo;ll configure our environment for Typescript and Mocha testing.&lt;/p&gt;
&lt;h2 id="poor-mans-dual-factor-authentication-via-a-password-of-the-day"&gt;Poor man&amp;rsquo;s dual factor authentication via a password of the day&lt;/h2&gt;



&lt;p&gt;I&amp;rsquo;m the technical lead for an enterprise application which is in use by about 100 large multinational corporates. As part of the installation process, we ask for a registration code which is based on the date. The customer has to call us to get the password of the day. This gives us an opportunity to engage with the customer and also gives us little more control. It&amp;rsquo;s a simple form of dual factor authorization where one of the factors requires a phone call.&lt;/p&gt;</description></item></channel></rss>